Skip to content

Commit b0c35de

Browse files
Time: 44 ms (54.09%) | Memory: 45.6 MB (50.89%) - LeetSync
1 parent c48b51f commit b0c35de

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.HashMap;
2+
3+
class Solution {
4+
public int findTheLongestSubstring(String s) {
5+
int n = s.length();
6+
int mask = 0;
7+
int maxLength = 0;
8+
HashMap<Integer, Integer> m = new HashMap<>();
9+
m.put(0, -1);
10+
11+
for (int i = 0; i < n; i++) {
12+
char c = s.charAt(i);
13+
if (c == 'a') mask ^= (1 << 0);
14+
else if (c == 'e') mask ^= (1 << 1);
15+
else if (c == 'i') mask ^= (1 << 2);
16+
else if (c == 'o') mask ^= (1 << 3);
17+
else if (c == 'u') mask ^= (1 << 4);
18+
19+
if (m.containsKey(mask)) {
20+
maxLength = Math.max(maxLength, i - m.get(mask));
21+
} else {
22+
m.put(mask, i);
23+
}
24+
}
25+
return maxLength;
26+
}
27+
}

0 commit comments

Comments
 (0)