[ Launch: test ] f688cdeeb78e9349a446 by PradipShrestha[ Launch: test ] 4653053 by enjalot[ Launch: test ] 4652017 by enjalot[ Launch: test ] 4582399 by enjalot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Heap { | |
buildHeaps(nums) { | |
for (let i = Math.ceil(nums.length / 2) - 1; i >= 0; i--) { | |
this.heapify(nums, i) | |
} | |
} | |
heapify(nums, i) { | |
let l = i * 2 + 1 | |
let r = l + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const partition = (l, r) => { | |
let p = Math.floor(l + (r - l) / 2) | |
let pivot = nums[p] | |
let i = l | |
let j = r | |
while (i <= j) { | |
while (pivot > nums[i]) { | |
i++ | |
} | |
while (pivot < nums[j]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wrap = (text, length) => { | |
const words = text.split(' ') | |
let line = '' | |
let lastWord = '' | |
const result = [] | |
for (let i = 0; i < words.length; i++) { | |
if (length > (words[i].length + line.length)) { | |
line += words[i] + ' ' | |
continue | |
} |