chenye-814 / DTSTRCT-ALGRTHM

0 stars 0 forks source link

Jan-02 Detect Capital #7

Open chenye-814 opened 1 year ago

chenye-814 commented 1 year ago

https://leetcode.com/problems/detect-capital/description/

chenye-814 commented 1 year ago
view code ```rust use std::str::Chars; impl Solution { pub fn detect_capital_use(word: String) -> bool { fn check_consistency(lower_flag: bool, mut chars: Chars) -> bool { while let Some(char) = chars.next() { if char.is_lowercase() != lower_flag { return false } } return true } let mut chars = word.chars(); let first_char = chars.next().unwrap(); if first_char.is_lowercase() { return check_consistency(true, chars) } if let Some(second_char) = chars.next() { return check_consistency(second_char.is_lowercase(), chars) } return true } } ```