Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jan-02 Detect Capital #7

Open
chenye-814 opened this issue Jan 2, 2023 · 1 comment
Open

Jan-02 Detect Capital #7

chenye-814 opened this issue Jan 2, 2023 · 1 comment

Comments

@chenye-814
Copy link
Owner

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

@chenye-814
Copy link
Owner Author

view code
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

    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant