forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_520.java
49 lines (47 loc) · 1.66 KB
/
_520.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.fishercoder.solutions;
public class _520 {
public static class Solution1 {
public boolean detectCapitalUse(String word) {
char[] words = word.toCharArray();
boolean firstLetterCap = false;
if (Character.isUpperCase(words[0])) {
firstLetterCap = true;
}
if (firstLetterCap) {
if (words.length >= 2) {
int i = 2;
if (Character.isUpperCase(words[1])) {
//then all following must be all uppercase
while (i < words.length) {
if (!Character.isUpperCase(words[i])) {
return false;
}
i++;
}
return true;
} else {
//then all following must be all lowercase
while (i < words.length) {
if (!Character.isLowerCase(words[i])) {
return false;
}
i++;
}
return true;
}
}
return true;
} else {
//then all following must be all lowercase
int i = 1;
while (i < words.length) {
if (!Character.isLowerCase(words[i])) {
return false;
}
i++;
}
return true;
}
}
}
}