aboutsummaryrefslogtreecommitdiff
path: root/other/detect_capital.rs
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-03-10 00:36:13 -0600
committerJack Sangdahl <[email protected]>2025-03-10 00:36:13 -0600
commit7c60dee83b436e8e8a667bf9f191beced8de4fc3 (patch)
treeeb7a24ee2067f92245c57bb118e85a1baf15df50 /other/detect_capital.rs
parent5d7cdc215e4ba1ec4cbb24c084cccb5e5e641468 (diff)
downloadleetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.tar.gz
leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.zip
chore: move cpp and rust code to directory
Diffstat (limited to 'other/detect_capital.rs')
-rw-r--r--other/detect_capital.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/other/detect_capital.rs b/other/detect_capital.rs
new file mode 100644
index 0000000..454381d
--- /dev/null
+++ b/other/detect_capital.rs
@@ -0,0 +1,20 @@
+struct Solution;
+
+impl Solution {
+ pub fn detect_capital_use(word: String) -> bool {
+ let v: Vec<char> = word.chars().collect();
+ if v[0].is_lowercase() {
+ return v.iter().all(|&c| c.is_lowercase());
+ }
+ if v.len() > 1 {
+ let b = v[1].is_lowercase();
+ return v.iter().skip(1).all(|&c| c.is_lowercase() == b);
+ }
+ true
+ }
+}
+
+fn main() {
+ let word = String::from("USA");
+ print!("{}", Solution::detect_capital_use(word)); //true
+}