diff --git "a/\354\243\274\353\247\220/haseung/Week18/H-index.js" "b/\354\243\274\353\247\220/haseung/Week18/H-index.js" new file mode 100644 index 00000000..e7636354 --- /dev/null +++ "b/\354\243\274\353\247\220/haseung/Week18/H-index.js" @@ -0,0 +1,12 @@ +function solution(citations) { + citations.sort((a, b) => b - a); + + let answers = 0; + for (let i = 0; i < citations.length; i++) { + if (i < citations[i]) { + answers++; + } + } + + return answers; +} diff --git "a/\354\243\274\353\247\220/haseung/Week18/leetcode/1689.js" "b/\354\243\274\353\247\220/haseung/Week18/leetcode/1689.js" new file mode 100644 index 00000000..d3379e9c --- /dev/null +++ "b/\354\243\274\353\247\220/haseung/Week18/leetcode/1689.js" @@ -0,0 +1,7 @@ +/** + * @param {string} n + * @return {number} + */ +var minPartitions = function (n) { + return [...n].reduce((acc, cur) => Math.max(acc, cur)); +}; diff --git "a/\354\243\274\353\247\220/haseung/Week18/\355\212\234\355\224\214.js" "b/\354\243\274\353\247\220/haseung/Week18/\355\212\234\355\224\214.js" new file mode 100644 index 00000000..42e04231 --- /dev/null +++ "b/\354\243\274\353\247\220/haseung/Week18/\355\212\234\355\224\214.js" @@ -0,0 +1,27 @@ +function solution(s) { + const answer = []; + // console.log(s.slice(2, s.length - 2).split("},{")) //[ '2', '2,1', '2,1,3', '2,1,3,4' ] + // console.log(s.slice(2, s.length - 2).split("},{").map(str=>str.split(',').map(Number).)) //[ [ 2 ], [ 2, 1 ], [ 2, 1, 3 ], [ 2, 1, 3, 4 ] ] + // s.slice(2, s.length - 2) + // .split("},{") + // .map((str) => str.split(",").map(Number)) + // .sort((a, b) => a.length - b.length) + // .flatMap((arr) => { + // arr.map((v) => { + // if (!answer.includes(v)) answer.push(v); + // }); + // }); + // return answer; + + const splited = s.slice(2, s.length - 2).split("},{"); + const sortedArrayAfterSplit = splited + .map((str) => str.split(",").map(Number)) + .sort((a, b) => a.length - b.length); + + sortedArrayAfterSplit.flatMap((arr) => { + arr.map((value) => { + if (!answer.includes(value)) answer.push(value); + }); + }); + return answer; +} diff --git "a/\354\243\274\353\247\220/haseung/Week18/\355\226\211\353\240\254\354\235\230\352\263\261\354\205\210.js" "b/\354\243\274\353\247\220/haseung/Week18/\355\226\211\353\240\254\354\235\230\352\263\261\354\205\210.js" new file mode 100644 index 00000000..eb1b2ac1 --- /dev/null +++ "b/\354\243\274\353\247\220/haseung/Week18/\355\226\211\353\240\254\354\235\230\352\263\261\354\205\210.js" @@ -0,0 +1,13 @@ +function solution(arr1, arr2) { + const [row, col] = [arr1.length, arr2[0].length]; //3 2 + let answer = new Array(row); + for (let i = 0; i < row; i++) { + answer[i] = new Array(col); + } + for (let i = 0; i < row; i++) { + for (let j = 0; j < col; j++) { + answer[i][j] = arr1[i].reduce((acc, val, index) => acc + val * arr2[index][j], 0); + } + } + return answer; +} diff --git "a/\354\243\274\353\247\220/haseung/Week19/leetcode/1476.js" "b/\354\243\274\353\247\220/haseung/Week19/leetcode/1476.js" new file mode 100644 index 00000000..e69de29b diff --git "a/\354\243\274\353\247\220/haseung/Week19/\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.js" "b/\354\243\274\353\247\220/haseung/Week19/\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.js" new file mode 100644 index 00000000..050e66b2 --- /dev/null +++ "b/\354\243\274\353\247\220/haseung/Week19/\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.js" @@ -0,0 +1,24 @@ +function solution(s) { + const pair = { "}": "{", "]": "[", ")": "(" }; + + const arr = s.split(""); + let result = 0; + const isValid = (arr) => { + const stack = []; + for (let i = 0; i < arr.length; i++) { + const element = arr[i]; + if (pair[element] === undefined) stack.push(element); + else { + if (stack[stack.length - 1] !== pair[element]) return false; + stack.pop(); + } + } + if (stack.length) return false; + return true; + }; + for (let i = 0; i < s.length; i++) { + if (isValid(arr)) result++; + arr.push(arr.shift()); + } + return result; +} diff --git "a/\354\243\274\353\247\220/haseung/Week19/\352\270\260\353\212\245\352\260\234\353\260\234.js" "b/\354\243\274\353\247\220/haseung/Week19/\352\270\260\353\212\245\352\260\234\353\260\234.js" new file mode 100644 index 00000000..2eba5a27 --- /dev/null +++ "b/\354\243\274\353\247\220/haseung/Week19/\352\270\260\353\212\245\352\260\234\353\260\234.js" @@ -0,0 +1,21 @@ +function solution(progresses, speeds) { + let answer = []; + let days = 1; + let cnt = 0; + let progress = 0; + + while (progresses[0]) { + progress = progresses[0] + speeds[0] * days; + if (progress >= 100) { + cnt++; + progresses.shift(); + speeds.shift(); + } else { + if (cnt > 0) answer.push(cnt); + days++; + cnt = 0; + } + } + answer.push(cnt); + return answer; +} diff --git "a/\354\243\274\353\247\220/haseung/Week19/\354\234\204\354\236\245.js" "b/\354\243\274\353\247\220/haseung/Week19/\354\234\204\354\236\245.js" new file mode 100644 index 00000000..da378f95 --- /dev/null +++ "b/\354\243\274\353\247\220/haseung/Week19/\354\234\204\354\236\245.js" @@ -0,0 +1,13 @@ +function solution(clothes) { + let answer = 1; + let obj = {}; + for (let i = 0; i < clothes.length; i++) { + obj[clothes[i][1]] = (obj[clothes[i][1]] || 1) + 1; + } + + for (let key in obj) { + answer *= obj[key]; + } + + return answer - 1; +}