MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / detect_capital_use

Function detect_capital_use

520-detect-capital.rs:1–22  ·  view source on GitHub ↗
(word: String)

Source from the content-addressed store, hash-verified

1pub fn detect_capital_use(word: String) -> bool {
2 let word_len = word.len();
3 let mut count = vec![0, 0];
4 let chars = word.chars().collect::<Vec<char>>();
5 let first_char = chars[0];
6 for c in chars {
7 if c.is_uppercase() {
8 count[0] += 1
9 } else {
10 count[1] += 1
11 }
12 }
13 if count[0] == 0 {
14 true
15 } else {
16 if count[1] == 0 {
17 true
18 } else {
19 count[1] == word_len - 1 && first_char.is_uppercase()
20 }
21 }
22}
23
24fn main() {
25 println!("{:?}", detect_capital_use("USA".to_string()));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected