Skip to content
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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]
17 changes: 17 additions & 0 deletions solutions/yesul/0128/[문제20]완주하지못한선수.js
Original file line number Diff line number Diff line change
@@ -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"
35 changes: 35 additions & 0 deletions solutions/yesul/0128/[문제21]영어끝말잇기.js
Original file line number Diff line number Diff line change
@@ -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]
13 changes: 13 additions & 0 deletions solutions/yesul/0128/[문제22]전화번호목록.js
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions solutions/yesul/0128/[문제23]할인행사.js
Original file line number Diff line number Diff line change
@@ -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
55 changes: 55 additions & 0 deletions solutions/yesul/0130/[문제28]트리순회.js
Original file line number Diff line number Diff line change
@@ -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 . .`))
67 changes: 67 additions & 0 deletions solutions/yesul/0130/[문제29]이진탐색트리구현.js
Original file line number Diff line number Diff line change
@@ -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]
11 changes: 11 additions & 0 deletions solutions/yesul/0130/[문제30]예상대진표.js
Original file line number Diff line number Diff line change
@@ -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;
}