diff --git "a/solutions/yesul/0128/[\353\254\270\354\240\23418]\353\221\220\352\260\234\354\235\230\354\210\230\353\241\234\355\212\271\354\240\225\352\260\222\353\247\214\353\223\244\352\270\260.js" "b/solutions/yesul/0128/[\353\254\270\354\240\23418]\353\221\220\352\260\234\354\235\230\354\210\230\353\241\234\355\212\271\354\240\225\352\260\222\353\247\214\353\223\244\352\270\260.js" new file mode 100644 index 0000000..f5bca35 --- /dev/null +++ "b/solutions/yesul/0128/[\353\254\270\354\240\23418]\353\221\220\352\260\234\354\235\230\354\210\230\353\241\234\355\212\271\354\240\225\352\260\222\353\247\214\353\223\244\352\270\260.js" @@ -0,0 +1,14 @@ +function solution(arr, target) { + for (let i = 0; i < arr.length; i++) { + for (let j = i + 1; j < arr.length; j++) { + if (arr[i] + arr[j] === target) { + return true; ll + } + } + } + + return false; +} + +console.log(solution([1, 2, 3, 4, 8], 6)); // true +console.log(solution([2, 3, 5, 9], 10)); // false \ No newline at end of file diff --git "a/solutions/yesul/0128/[\353\254\270\354\240\23419]\353\254\270\354\236\220\354\227\264\355\225\264\354\213\261\354\235\204\354\235\264\354\232\251\355\225\234\352\262\200\354\203\211\355\225\250\354\210\230\353\247\214\353\223\244.js" "b/solutions/yesul/0128/[\353\254\270\354\240\23419]\353\254\270\354\236\220\354\227\264\355\225\264\354\213\261\354\235\204\354\235\264\354\232\251\355\225\234\352\262\200\354\203\211\355\225\250\354\210\230\353\247\214\353\223\244.js" new file mode 100644 index 0000000..9c8de3a --- /dev/null +++ "b/solutions/yesul/0128/[\353\254\270\354\240\23419]\353\254\270\354\236\220\354\227\264\355\225\264\354\213\261\354\235\204\354\235\264\354\232\251\355\225\234\352\262\200\354\203\211\355\225\250\354\210\230\353\247\214\353\223\244.js" @@ -0,0 +1,8 @@ +// function solution(stringList, queryList) { +// return queryList.map((query) => stringList.includes(query)); +// } + +function solution(stringList, queryList) { +} + +console.log(solution(["apple", "banana", "charry"], ["banana", "kiwi", "melon", "apple"])); // [true, false, false, true] \ No newline at end of file diff --git "a/solutions/yesul/0128/[\353\254\270\354\240\23420]\354\231\204\354\243\274\355\225\230\354\247\200\353\252\273\355\225\234\354\204\240\354\210\230.js" "b/solutions/yesul/0128/[\353\254\270\354\240\23420]\354\231\204\354\243\274\355\225\230\354\247\200\353\252\273\355\225\234\354\204\240\354\210\230.js" new file mode 100644 index 0000000..97a0230 --- /dev/null +++ "b/solutions/yesul/0128/[\353\254\270\354\240\23420]\354\231\204\354\243\274\355\225\230\354\247\200\353\252\273\355\225\234\354\204\240\354\210\230.js" @@ -0,0 +1,17 @@ +function solution(participant, completion) { + // 1. reduce로 참가자 명단 만들기 + const userHash = participant.reduce((obj, cur) => { + obj[cur] = (obj[cur] || 0) + 1; + return obj; // 다음 루프로 객체를 넘겨줌 + }, {}); + + // 2. 완주자 처리 + for (const name of completion) { + userHash[name]--; + } + + // 3. 결과 반환 + return Object.keys(userHash).find(key => userHash[key] > 0); +} + +console.log(solution(["leo", "kiki", "eden"], ["eden", "kiki"])); // "leo" \ No newline at end of file diff --git "a/solutions/yesul/0128/[\353\254\270\354\240\23421]\354\230\201\354\226\264\353\201\235\353\247\220\354\236\207\352\270\260.js" "b/solutions/yesul/0128/[\353\254\270\354\240\23421]\354\230\201\354\226\264\353\201\235\353\247\220\354\236\207\352\270\260.js" new file mode 100644 index 0000000..a3152d5 --- /dev/null +++ "b/solutions/yesul/0128/[\353\254\270\354\240\23421]\354\230\201\354\226\264\353\201\235\353\247\220\354\236\207\352\270\260.js" @@ -0,0 +1,35 @@ +function solution(n, words) { + const answer = '' + + const usedWords = new Set(); + + const findIndex = words.findIndex((word, index) => { + if (index === 0) { + usedWords.add(word); + return false; + } + + const isWrong = words[index - 1].at(-1) !== word.at(0) + const isDuplicated = usedWords.has(word); + + if (isWrong || isDuplicated) { + return true; + } + + usedWords.add(word); + return false; + }); + + if (findIndex === -1) return [0, 0] + + + const userNum = (findIndex % n) + 1; + const wrongCountNum = Math.ceil((findIndex + 1) / n); + + + return [userNum, wrongCountNum]; +} + +console.log(solution(3, ["tank", "kick", "know", "wheel", "land", "dream", "mother", "robot", "tank"])); // [3,3] +console.log(solution(5, ["hello", "observe", "effect", "take", "either", "recognize", "encourage", "ensure", "establish", "hang", "gather", "refer", "reference", "estimate", "executive"])); // [0,0] +console.log(solution(2, ["hello", "one", "even", "never", "now", "world", "draw"])); // [1,3] \ No newline at end of file diff --git "a/solutions/yesul/0128/[\353\254\270\354\240\23422]\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.js" "b/solutions/yesul/0128/[\353\254\270\354\240\23422]\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.js" new file mode 100644 index 0000000..59bc6a9 --- /dev/null +++ "b/solutions/yesul/0128/[\353\254\270\354\240\23422]\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.js" @@ -0,0 +1,13 @@ +function solution(phone_book) { + phone_book.sort(); + for (let i = 0; i < phone_book.length - 1; i++) { + if (phone_book[i + 1].startsWith(phone_book[i])) { + return false; + } + } + return true; +} + +console.log(solution(["119", "97674223", "1195524421"])); // false +console.log(solution(["123", "456", "789"])); // true +console.log(solution(["12", "123", "1235", "567", "88"])); // false \ No newline at end of file diff --git "a/solutions/yesul/0128/[\353\254\270\354\240\23423]\355\225\240\354\235\270\355\226\211\354\202\254.js" "b/solutions/yesul/0128/[\353\254\270\354\240\23423]\355\225\240\354\235\270\355\226\211\354\202\254.js" new file mode 100644 index 0000000..8d88946 --- /dev/null +++ "b/solutions/yesul/0128/[\353\254\270\354\240\23423]\355\225\240\354\235\270\355\226\211\354\202\254.js" @@ -0,0 +1,54 @@ +function solution(want, number, discount) { + let answer = 0; + + const wantMap = want.reduce((acc, cur, index) => { + acc[cur] = number[index]; + return acc; + }, {}); + + // 0일째 ~ 9일째 + // 마트 할인 기간이 끝나기 10일 전까지만 가입할 있기 때문에 + // discount.length - 10으로 제한 + for (let i = 0; i <= discount.length - 10; i++) { + // N일차의 할일 목록을 담을 객체 + const discountMap = {}; + + // 가입한 날 부터 10일동안 어떤 물품이 몇 개 있는지 + for (let j = i; j < i + 10; j++) { + const item = discount[j]; + discountMap[item] = (discountMap[item] || 0) + 1; + } + + // 사고 싶던 것과 개수가 일치하는지 확인 + if (isMatch(wantMap, discountMap)) { + answer++; // 성공횟수 추가 + } + } + + + function isMatch(wantMap, discountMap) { + for (const key in wantMap) { + if (discountMap[key] !== wantMap[key]) return false; + } + return true; + } + + return answer; +} + + + +console.log( + solution( + ["banana", "apple", "rice", "pork", "pot"], + [3, 2, 2, 2, 1], + ["chicken", "apple", "apple", "banana", "rice", "apple", "pork", "banana", "pork", "rice", "pot", "banana", "apple", "banana"] + ) +) // 3 + +console.log( + solution(["apple"], + [10], + ["banana", "banana", "banana", "banana", "banana", "banana", "banana", "banana", "banana", "banana"], + ) +) // 0 \ No newline at end of file diff --git "a/solutions/yesul/0130/[\353\254\270\354\240\23428]\355\212\270\353\246\254\354\210\234\355\232\214.js" "b/solutions/yesul/0130/[\353\254\270\354\240\23428]\355\212\270\353\246\254\354\210\234\355\232\214.js" new file mode 100644 index 0000000..8d9debc --- /dev/null +++ "b/solutions/yesul/0130/[\353\254\270\354\240\23428]\355\212\270\353\246\254\354\210\234\355\232\214.js" @@ -0,0 +1,55 @@ +function solution(input) { + const [n, ...trees] = input.split('\n') + const tree = {}; + + for (let i = 1; i <= n; i++) { + const [node, left, right] = trees[i - 1].split(' '); + tree[node] = [left, right]; + } + + let result = ''; + + // 전위 순회 + function preOrder(node) { + if (node === '.') return; + const [left, right] = tree[node]; + result += node; + preOrder(left); + preOrder(right); + } + + // 중위 순회 + function inOrder(node) { + if (node === '.') return; + const [left, right] = tree[node]; + inOrder(left); + result += node; + inOrder(right); + } + + // 후위 순회 + function postOrder(node) { + if (node === '.') return; + const [left, right] = tree[node]; + postOrder(left); + postOrder(right); + result += node; + } + + preOrder("A"); + result += "\n"; + inOrder("A"); + result += "\n"; + postOrder("A"); + + return result; +} + +console.log(solution(`7 +A B C +B D . +C E F +E . . +F . G +D . . +G . .`)) \ No newline at end of file diff --git "a/solutions/yesul/0130/[\353\254\270\354\240\23429]\354\235\264\354\247\204\355\203\220\354\203\211\355\212\270\353\246\254\352\265\254\355\230\204.js" "b/solutions/yesul/0130/[\353\254\270\354\240\23429]\354\235\264\354\247\204\355\203\220\354\203\211\355\212\270\353\246\254\352\265\254\355\230\204.js" new file mode 100644 index 0000000..525ec3f --- /dev/null +++ "b/solutions/yesul/0130/[\353\254\270\354\240\23429]\354\235\264\354\247\204\355\203\220\354\203\211\355\212\270\353\246\254\352\265\254\355\230\204.js" @@ -0,0 +1,67 @@ +class Node { + constructor(value) { + this.value = value; + this.left = null; + this.right = null; + } +} + +class BinarysearchTree { + constructor() { + this.root = null; + } + + insert(value) { + const newNode = new Node(value); + if (this.root === null) { + this.root = newNode; + } else { + this.insertNode(this.root, newNode); + } + } + + insertNode(node, newNode) { + if (node.value > newNode.value) { + if (node.left === null) { + node.left = newNode; + } else { + this.insertNode(node.left, newNode); + } + } else { + if (node.right === null) { + node.right = newNode; + } else { + this.insertNode(node.right, newNode) + } + } + } + + search(value) { + let current = this.root; + + while (current) { + if (current.value === value) { + return true; + } else if (current.value > value) { + current = current.left; + } else { + current = current.right; + } + } + + return false; + } +} + +function solution(list, searchList) { + const tree = new BinarysearchTree(); + list.forEach(node => tree.insert(node)); + + return searchList.map(node => tree.search(node)); +} + +console.log(solution([5, 3, 8, 4, 2, 1, 7, 10], [1, 2, 5, 6])) +// [true, true, true, false] + +console.log(solution([1, 3, 5, 7, 9], [2, 4, 6, 8, 10])) +// [false, false, false, false, false] \ No newline at end of file diff --git "a/solutions/yesul/0130/[\353\254\270\354\240\23430]\354\230\210\354\203\201\353\214\200\354\247\204\355\221\234.js" "b/solutions/yesul/0130/[\353\254\270\354\240\23430]\354\230\210\354\203\201\353\214\200\354\247\204\355\221\234.js" new file mode 100644 index 0000000..466e578 --- /dev/null +++ "b/solutions/yesul/0130/[\353\254\270\354\240\23430]\354\230\210\354\203\201\353\214\200\354\247\204\355\221\234.js" @@ -0,0 +1,11 @@ +function solution(n, a, b) { + let round = 0; + while (a !== b) { + a = Math.ceil(a / 2); + b = Math.ceil(b / 2); + + round++; + } + + return round; +} \ No newline at end of file