Skip to content

Commit 4c0c2da

Browse files
committed
Leetcode August challenge day 1
1 parent d9ceb4b commit 4c0c2da

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.leetcode.AugustChallenge.week1;
2+
3+
public class DetectCapital {
4+
5+
public boolean detectCapitalUse(String word) {
6+
int n = word.length();
7+
if (n == 1)
8+
return true;
9+
10+
if (Character.isUpperCase(word.charAt(0)) && Character.isUpperCase(word.charAt(1))) {
11+
for (int i = 2; i < n; i++) {
12+
if (Character.isLowerCase(word.charAt(i)))
13+
return false;
14+
}
15+
} else {
16+
for (int i = 1; i < n; i++) {
17+
if (Character.isUpperCase(word.charAt(i)))
18+
return false;
19+
}
20+
}
21+
return true;
22+
}
23+
24+
public boolean detectCapitalUseUsingRegex(String word) {
25+
return word.matches("[A-Z]*|.[a-z]*");
26+
}
27+
}

0 commit comments

Comments
 (0)