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 quickSort(arr){ | |
if(arr.length === 0) return arr; | |
let pivot = arr.pop(); | |
let i = -1; | |
for(j = 0; j < arr.length; j++){ | |
if(arr[j] <= pivot){ | |
i++; | |
[arr[i], arr[j]] = [arr[j], arr[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 fibonacci(n, memo = {0: 0, 1: 1}){ | |
if(memo[n] !== undefined) return memo[n]; | |
memo[n] = fibonacci(n-1, memo) + fibonacci(n-2, memo); | |
return memo[n]; | |
} |
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 solution(n, arr1, arr2){ | |
let result = []; | |
for(i = 0; i < n; i ++){ | |
let row = (arr1[i] | arr2[i]).toString(2); | |
row = row.replace(/1/g, '#'); | |
row = row.replace(/0/g, ' '); | |
result.push(row) | |
} |
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 solution(n) { | |
let result = []; | |
result = result.concat(move(n, 1, 3)); | |
return result | |
} | |
function move(depth, source, target){ | |
if(depth === 1) return [[source, target]]; |
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 solution(s){ | |
let {length} = s; | |
while(length){ | |
for(let i = 0; i + length <= s.length; i++){ | |
if(isPalin(s.slice(i,i+length))) return length; | |
} | |
length-- | |
} | |
} |
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 solution(n) { | |
let result = 0; | |
for(let i = 1; i <= n; i++){ | |
let temp = 0; | |
for(let j = i; temp < n; j++){ | |
temp += 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
function solution(n) { | |
var answer = ''; | |
while(n > 0){ | |
const remainder = n%3 || 3; | |
answer = (remainder === 3 ? 4 : remainder) + answer; | |
n = (n-remainder)/3; | |
} | |
return answer; |
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
var invertTree = function(root) { | |
if(root === null) return null; | |
const [invertedLeft, invertedRight] = [invertTree(root.left), invertTree(root.right)]; | |
([root.left, root.right] = [invertedRight, invertedLeft]); | |
return root; | |
}; |
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
var singleNumber = function(nums) { | |
return nums.reduce((acc,cur) => acc^cur); | |
}; |
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 mergeTrees(t1, t2){ | |
if(t1 === null || t2 === null) return t1 ? t1 : t2 ? t2 : null; | |
let newTree = new TreeNode(t1.val+t2.val); | |
newTree.left = mergeTrees(t1.left, t2.left); | |
newTree.right = mergeTrees(t1.right, t2.right); | |
return newTree; | |
} |
NewerOlder