We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 49bb2ec commit ac8a3cfCopy full SHA for ac8a3cf
1371.每个元音包含偶数次的最长子字符串.js
@@ -0,0 +1,23 @@
1
+/**
2
+ * @param {string} s
3
+ * @return {number}
4
+ */
5
+var findTheLongestSubstring = function(s) {
6
+ const lst = new Array(32).fill(-1);
7
+ let result = 0;
8
+ let h = 0;
9
+ lst[h] = 0;
10
+ for (let i = 0; i < s.length; i++) {
11
+ if (s[i] === 'a') h ^= (1 << 0);
12
+ else if (s[i] === 'e') h ^= (1 << 1);
13
+ else if (s[i] === 'i') h ^= (1 << 2);
14
+ else if (s[i] === 'o') h ^= (1 << 3);
15
+ else if (s[i] === 'u') h ^= (1 << 4);
16
+ if (lst[h] >= 0) {
17
+ result = Math.max(result, i + 1 - lst[h]);
18
+ } else {
19
+ lst[h] = i + 1;
20
+ }
21
22
+ return result;
23
+};
0 commit comments