-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcode1704_StringHalvesAlike.java
More file actions
36 lines (26 loc) · 1.13 KB
/
Copy pathleetcode1704_StringHalvesAlike.java
File metadata and controls
36 lines (26 loc) · 1.13 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
public class leetcode1704_StringHalvesAlike {
public boolean halvesAreAlike(String s) {
int len = s.length(), count1=0, count2=0;
for(int i=0;i<len/2;i++){
if(s.charAt(i) == 'a' || s.charAt(i) == 'e' || s.charAt(i) == 'i' || s.charAt(i) == 'o' || s.charAt(i) == 'u' ||
s.charAt(i) == 'A' || s.charAt(i) == 'E' || s.charAt(i) == 'I' || s.charAt(i) == 'O' || s.charAt(i) == 'U') {
count1++;
}
}
for(int i=len/2;i<len;i++){
if(s.charAt(i) == 'a' || s.charAt(i) == 'e' || s.charAt(i) == 'i' || s.charAt(i) == 'o' || s.charAt(i) == 'u' ||
s.charAt(i) == 'A' || s.charAt(i) == 'E' || s.charAt(i) == 'I' || s.charAt(i) == 'O' || s.charAt(i) == 'U') {
count2++;
}
}
if(count1 == count2)
return true;
else
return false;
}
public static void main(String[] args) {
leetcode1704_StringHalvesAlike obj = new leetcode1704_StringHalvesAlike();
boolean res = obj.halvesAreAlike("AbCdEfGh");
System.out.println(res);
}
}