-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path520.detect-capital.java
More file actions
28 lines (26 loc) · 989 Bytes
/
Copy path520.detect-capital.java
File metadata and controls
28 lines (26 loc) · 989 Bytes
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
class Solution {
public boolean detectCapitalUse(String word) {
int caps = 0;
int small = 0;
char[] c = word.toCharArray();
int f = 0;
for(int i=0;i<c.length;i++){
if(Character.isDigit(c[i]))
return false;
if(i ==0 && c[i]==Character.toUpperCase(c[i]))
f = 1;
if(c[i] == Character.toUpperCase(c[i]))
caps++;
else if(c[i] == Character.toLowerCase(c[i]))
small++;
}
return caps == word.length() || small == word.length() || (f == 1 && small == word.length()-1)? true:false;
// if(word.equals(word.toUpperCase()))
// return true;
// else if(word.equals(word.toLowerCase()))
// return true;
// else if(word.equals(Character.toUpperCase(word.charAt(0))+word.substring(1)))
// return true;
// return false;
}
}