kingeasternsun 发表于 2021-11-20 15:58
Tags:rust,iterator,leetcode
383 题目
impl Solution { pub fn can_construct(ransom_note: String, magazine: String) -> bool { let mut m = vec![0u32; 26]; magazine .as_bytes() .iter() .for_each(|x| m[(x - b'a') as usize] = m[(x - b'a') as usize] + 1); ransom_note.as_bytes().iter().all(|x| { if m[(x - b'a') as usize] == 0 { return false; } m[(x - b'a') as usize] = m[(x - b'a') as usize] - 1; true }) } }
👇 dlhxzb:
pub fn detect_capital_use(word: String) -> bool { let mut word = word.chars(); let first_is_upper = if let Some(first) = word.next(){ first.is_uppercase() } else { return true; }; let mut second_is_upper = None; !word.any(|c|{ if second_is_upper.is_none() { second_is_upper = Some(c.is_uppercase()) } (!first_is_upper && c.is_uppercase()) || second_is_upper != Some(c.is_uppercase()) }) }
评论区
写评论383 题目
漂亮
👇
dlhxzb: