-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path520.java
More file actions
63 lines (58 loc) · 1.68 KB
/
520.java
File metadata and controls
63 lines (58 loc) · 1.68 KB
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
63
__________________________________________________________________________________________________
sample 1 ms submission
class Solution {
public boolean detectCapitalUse(String word) {
String lWord = word.toLowerCase();
//before lowercase
if(lWord.equals(word)) {
return true;
}
int diff=0;
//before all caps
for(int i=0;i<word.length();i++) {
if(word.charAt(i) != lWord.charAt(i)) {
diff++;
}
}
if(diff==1 && lWord.charAt(0) != word.charAt(0)) {
return true;
}
if(diff==word.length()) {
return true;
}
return false;
}
}
__________________________________________________________________________________________________
sample 36684 kb submission
class Solution {
public boolean detectCapitalUse(String word) {
int len=word.length();
int u=0,i,l=0,c=0;
char ch,ch1;
for(i=0;i<len;i++)
{
ch=word.charAt(i);
if(ch>=65 && ch<=90)
u++;
}
for(i=0;i<len;i++)
{
ch=word.charAt(i);
if(ch>=97 && ch<=122)
l++;
}
ch1=word.charAt(0);
if(ch1>=65 && ch1<=90 ) c=1;
for(i=1;i<len;i++)
{
ch=word.charAt(i);
if (ch>=97 && ch<=122) c++;
}
if(u==len||l==len||c==len)
return true;
else
return false;
}
}
__________________________________________________________________________________________________