Skip to content

Commit 5071767

Browse files
committed
added reverse-vowels
1 parent 6eec084 commit 5071767

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const reverseVowels = (s: string) => {
2+
const vowelSet = new Set<string>([
3+
'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U',
4+
])
5+
const str = Array.from(s);
6+
let l = 0;
7+
let r = s.length - 1;
8+
9+
while (l < r) {
10+
while (!vowelSet.has(str[l]) && l < r) l++;
11+
while (!vowelSet.has(str[r]) && l < r) r--;
12+
if (l < r) {
13+
[str[l++], str[r--]] = [str[r], str[l]]
14+
}
15+
}
16+
return str.join('')
17+
};

src/main.ts

+12-21
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
1-
import { minGroupsDBG } from "./array/intervals/min-groups";
2-
import { isReflectedDBG } from "./array/hash_table/is-reflected";
3-
import { Heap } from "./heap/utilities/heap";
1+
// 3 = 9 sec
42

53

6-
function maxSlidingWindow(nums: number[], k: number): number[] {
7-
const heap = new Heap<[number, number]>((a, b) => a[0] > b[0]);
8-
const result: number[] = [];
9-
10-
for (let i = 0; i < k; i++) {
11-
heap.push([nums[i], i]);
12-
}
13-
14-
for (let i = k - 1; i < nums.length; i++) {
15-
heap.push([nums[i], i]);
16-
while (heap.top()[1] < i - k + 1) {
17-
heap.pop();
18-
}
19-
result.push(heap.top()[0]);
4+
async function rateLimiter(str: string[], time: number) {
5+
for (let i = 0; i < str.length; i++) {
6+
await new Promise(res => setTimeout(res, time));
7+
console.log(str[i]);
208
}
21-
return result;
229
}
23-
//test
24-
const nums = [1,-1], k = 1;
2510

26-
console.log(maxSlidingWindow(nums, k));
11+
const strs = [
12+
'one',
13+
'two',
14+
'three',
15+
]
16+
17+
rateLimiter(strs, 3000);

0 commit comments

Comments
 (0)