-
Notifications
You must be signed in to change notification settings - Fork 0
/
520DetectCapital.java
62 lines (59 loc) · 1.5 KB
/
520DetectCapital.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
50
51
52
53
54
55
56
57
58
59
60
61
62
public class Solution {
public boolean detectCapitalUse(String word) {
int[] help = new int[word.length()];
int length = word.length();
for(int i=0;i<length;i++){
help[i]=word.charAt(i)-'a';
}
// if(AllCapital(help)){
// return true;
// }
// if(firstCapital(help)){
// return true;
// }
// if(NonCapital(help)){
// return true;
// }
// return false;
if(help[0]<0){
if(AllCapital(help)){
return true;
}
if(firstCapital(help)){
return true;
}
}else{
if(NonCapital(help)){
return true;
}
}
return false;
}
private boolean AllCapital(int[]help){
for(int i =0;i<help.length;i++){
if(help[i]>=0){
return false;
}
}
return true;
}
private boolean firstCapital(int[]help){
boolean position1 = help[0]>=0? false:true;
boolean position2 = true;
for(int i=1;i<help.length;i++){
if(help[i]<0){
position2 = false;
break;
}
}
return position1&position2;
}
private boolean NonCapital(int[]help){
for(int i=0;i<help.length;i++){
if(help[i]<0){
return false;
}
}
return true;
}
}