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
| macro_rules! make_literal_maker { | |
| ($name:ident : $ty:ident) => { | |
| macro_rules! $name { | |
| ($n:expr) => {{ | |
| const fn digits_len(mut n: $ty) -> ::core::primitive::usize { | |
| if n == 0 { | |
| return 1; | |
| } | |
| let mut n_digits = 0; | |
| #[allow(unused_comparisons)] |
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; |