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
function Node(value, parent = null){ | |
this.value = value | |
this.left = null | |
this.right = null | |
this.parent = parent | |
} | |
// create tree |
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
function Node(value, parent = null){ | |
this.value = value | |
this.left = null | |
this.right = null | |
this.parent = parent | |
} | |
// create tree |
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
function Node(value, parent = null){ | |
this.value = value | |
this.left = null | |
this.right = null | |
this.parent = parent | |
} | |
// create tree |
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
function sum(x, y){ | |
if(y === 0) return x | |
return sum( x^y, (x&y)<<1 ) | |
} | |
function multiply(x, y){ | |
if(x ===0 || y ===0) return 0 |
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 FenwickTree{ | |
constructor(array){ | |
this.source = [...array] | |
this.length = this.source.length; | |
this.fenwick = new Array(array.length+1).fill(0) | |
this.build(); | |
} | |
build(){ | |
for(let i = 0; i < this.length; i++) |
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
function animate({ timing, duration, draw }){ | |
return new Promise((resolve, reject) => { | |
const start = performance.now(); | |
function animation(time){ | |
const progress = Math.min((time-start)/duration, 1); | |
const visualProgress = timing ? timing(progress): progress; | |
draw(visualProgress); | |
if(progress < 1) requestAnimationFrame(animation) |
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 Calendar { | |
constructor(selector){ | |
this.MONTHS= ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] | |
this.root = document.querySelector(selector); | |
this.activeDateTime = new Date(); | |
this.render(); | |
this.attachEvents(); | |
} | |
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
function getListMiddle(head){ | |
let slow = head; | |
let fast = head; | |
let moveBoth = false; | |
// to get second element, in case of two mid-nodes, use 'fast' instead of 'fast.next' | |
while(fast.next){ | |
if(moveBoth){ | |
slow = slow.next; | |
fast = fast.next; |
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 Solution: | |
def sortColors(self, nums: List[int]) -> None: | |
""" | |
Do not return anything, modify nums in-place instead. | |
""" | |
start, end = 0, len(nums)-1 | |
i = start |
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
def compress(arr): | |
arr.sort(); | |
compress_map = {} | |
val = 1 | |
for el in arr: | |
if el not in compress_map: | |
compress_map[el] = val | |
val += 1 | |
NewerOlder