Skip to content

Commit 6f498ae

Browse files
committed
❌ [1456] TLE
1 parent 1f3856f commit 6f498ae

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

1456/my_solution.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @param {string} s
3+
* @param {number} k
4+
* @return {number}
5+
*/
6+
var maxVowels = function (s, k) {
7+
let l = 0, maxCount = 0, vowelSet = new Set(["a", "e", "i", "o", "u"])
8+
s = s.split("")
9+
console.log(s)
10+
console.log(vowelSet)
11+
12+
while ((l + k - 1) < s.length) {
13+
let tmpCount = 0;
14+
for (let i = l; i < (l + k); i++) {
15+
if (vowelSet.has(s[i])) tmpCount++;
16+
}
17+
18+
maxCount = Math.max(maxCount, tmpCount)
19+
20+
l++;
21+
}
22+
23+
return maxCount
24+
};
25+
26+
"abciiidef", k = 3
27+
28+
// ['a', 'b', 'c', 'i', 'i', 'i', 'd', 'e', 'f']
29+
let x =
30+
// maxVowels("abciiidef", 3)//3
31+
// maxVowels("aeiou", 2) //2
32+
maxVowels("leetcode", 3) //2
33+
34+
console.log("Res")
35+
console.log(x)

1456/solution.js

Whitespace-only changes.

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
- [1342. Number of Steps to Reduce a Number to Zero](./1342/)
104104
- [1365. How Many Numbers Are Smaller Than the Current Number](./1365/)
105105
- [1431. Kids With the Greatest Number of Candies](./1431/)
106+
- [1456. Maximum Number of Vowels in a Substring of Given Length](./1456/)
106107
- [1480. Running Sum of 1d Array](./1480/)
107108
- [1512. Number of Good Pairs](./1512/)
108109
- [1569. Number of Ways to Reorder Array to Get Same BST](./1569/)
@@ -163,7 +164,7 @@ Batch create:
163164
NOTE: JS IS HERE
164165
-->
165166
```ssh
166-
chapter=643 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
167+
chapter=1456 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
167168
```
168169
> then you can use `x` for quick debug.
169170

0 commit comments

Comments
 (0)