-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1704.java
26 lines (24 loc) · 1003 Bytes
/
_1704.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
package com.fishercoder.solutions.secondthousand;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.IntStream;
public class _1704 {
public static class Solution1 {
public boolean halvesAreAlike(String s) {
Set<Character> vowels =
new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'));
int firstHalfVowelsCount =
(int)
IntStream.range(0, s.length() / 2)
.filter(i -> vowels.contains(s.charAt(i)))
.count();
int secondHalfVowelsCount =
(int)
IntStream.range(s.length() / 2, s.length())
.filter(i -> vowels.contains(s.charAt(i)))
.count();
return firstHalfVowelsCount == secondHalfVowelsCount;
}
}
}