Skip to content

Commit d17680c

Browse files
add 1704
1 parent 59d0222 commit d17680c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1704|[Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1704.java) ||Easy|String|
1112
|1700|[Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1700.java) ||Easy|Array|
1213
|1694|[Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1694.java) ||Easy|String|
1314
|1690|[Stone Game VII](https://leetcode.com/problems/stone-game-vii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1690.java) ||Medium|DP|
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Arrays;
4+
import java.util.HashSet;
5+
import java.util.Set;
6+
import java.util.stream.IntStream;
7+
8+
public class _1704 {
9+
public static class Solution1 {
10+
public boolean halvesAreAlike(String s) {
11+
Set<Character> vowels = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'));
12+
int firstHalfVowelsCount = (int) IntStream.range(0, s.length() / 2).filter(i -> vowels.contains(s.charAt(i))).count();
13+
int secondHalfVowelsCount = (int) IntStream.range(s.length() / 2, s.length()).filter(i -> vowels.contains(s.charAt(i))).count();
14+
return firstHalfVowelsCount == secondHalfVowelsCount;
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)