Skip to content

Instantly share code, notes, and snippets.

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]];
}
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];
}
@youngdo212
youngdo212 / kakao.js
Created July 17, 2018 01:52
카카오 알고리즘 1번 문제
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)
}
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]];
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--
}
}
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;
}
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;
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;
};
var singleNumber = function(nums) {
return nums.reduce((acc,cur) => acc^cur);
};
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;
}