deno.land / x / masx200_leetcode_test@10.6.5 / wiggle-sort-ii / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function wiggleSort(nums: number[]): void { const bucket = Array<number>();
for (const num of nums) { bucket[num] = (bucket[num] ?? 0) + 1; } let j = bucket.length - 1;
for (let i = 1; i < nums.length; i += 2) { while ((bucket[j] ?? 0) === 0) { j--; }
nums[i] = j; bucket[j]--; } for (let i = 0; i < nums.length; i += 2) { while ((bucket[j] ?? 0) === 0) { j--; }
nums[i] = j; bucket[j]--; }}export default wiggleSort;
masx200_leetcode_test

Version Info

Tagged at
a year ago