This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::ops::{Deref, DerefMut}; | |
use std::cell::Cell; | |
#[derive(Default)] | |
struct Simple { | |
field: u32, | |
} | |
impl Simple { | |
fn new(field: u32) -> Self { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl Solution { | |
pub fn full_justify(words: Vec<String>, max_width: i32) -> Vec<String> { | |
let mut ret = Vec::new(); | |
let width = max_width as usize; | |
let mut words = &words[..]; | |
while let Some((first, rest)) = split_by_width(&mut words, width) { | |
if words.is_empty() { | |
ret.push(pack_left_justified(width, first, rest)); | |
} else{ | |
ret.push(pack(width, first, rest)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Node<T> { | |
item: T, | |
next: NextNode<T>, | |
} | |
type NextNode<T> = Option<Box<Node<T>>>; | |
impl<T> Node<T> { | |
fn replace_tail(&mut self, new_tail: NextNode<T>) -> NextNode<T> { | |
std::mem::replace(&mut self.next, new_tail) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(trace_macros)] | |
trace_macros!(true); | |
macro_rules! assert_ct_not_equal { | |
($a:tt, $b:tt) => { | |
#[deny(const_err)] | |
const _: () = { | |
macro_rules! is_a { | |
($a) => { true }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl Solution { | |
pub fn add_binary(a: String, b: String) -> String { | |
enum These { | |
Both(u8, u8), | |
Single(u8), | |
} | |
use These::*; | |
let len = a.len().max(b.len()) + 1; | |
let mut a = a.as_bytes().iter().rev().copied(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <array> | |
#include <memory> | |
#include <functional> | |
#include <optional> | |
class TrieNode { | |
public: | |
std::array<std::unique_ptr<TrieNode>, 26> next = {}; | |
bool has_word_end = false; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let width = 9_usize; | |
let total = width * width + 2; | |
let len = width * width * (width - 1) + width * 2; | |
let mut out = Vec::with_capacity(len); | |
for i in 0..width { | |
out.push([0, i + 1, 100]); | |
} | |
for layer in 0..width - 1 { | |
let base = layer * width + 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl Solution { | |
pub fn single_number(nums: Vec<i32>) -> i32 { | |
let compressed = nums.iter() | |
.map(|&n| evenly_space_bits(n as u32)) | |
.fold(0, |acc, n| omit_threes(acc + n)); | |
unspace_bits(compressed) as _ | |
} | |
} | |
fn evenly_space_bits(n: u32) -> u64 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let width = 9_usize; | |
let total = width * width + 2; | |
let len = width * width * (width - 1) + width * 2; | |
let mut out = Vec::with_capacity(len); | |
for i in 0..width { | |
out.push([0, i + 1, 100]); | |
} | |
for layer in 0..width - 1 { | |
let base = layer * width + 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 | |
[[0, 1, 100], [0, 2, 100], [0, 3, 100], [0, 4, 100], [0, 5, 100], [0, 6, 100], [0, 7, 100], [0, 8, 100], [0, 9, 100], [1, 10, 100], [1, 11, 100], [1, 12, 100], [1, 13, 100], [1, 14, 100], [1, 15, 100], [1, 16, 100], [1, 17, 100], [1, 18, 100], [2, 10, 100], [2, 11, 100], [2, 12, 100], [2, 13, 100], [2, 14, 100], [2, 15, 100], [2, 16, 100], [2, 17, 100], [2, 18, 100], [3, 10, 100], [3, 11, 100], [3, 12, 100], [3, 13, 100], [3, 14, 100], [3, 15, 100], [3, 16, 100], [3, 17, 100], [3, 18, 100], [4, 10, 100], [4, 11, 100], [4, 12, 100], [4, 13, 100], [4, 14, 100], [4, 15, 100], [4, 16, 100], [4, 17, 100], [4, 18, 100], [5, 10, 100], [5, 11, 100], [5, 12, 100], [5, 13, 100], [5, 14, 100], [5, 15, 100], [5, 16, 100], [5, 17, 100], [5, 18, 100], [6, 10, 100], [6, 11, 100], [6, 12, 100], [6, 13, 100], [6, 14, 100], [6, 15, 100], [6, 16, 100], [6, 17, 100], [6, 18, 100], [7, 10, 100], [7, 11, 100], [7, 12, 100], [7, 13, 100], [7, 14, 100], [7, 15, 100], [7, 16, 100], [7, 17, 100], [7, 18, 100], [8, 10, 100], [8, 11, |