728x90 배움 기록64 [프로그래머스] 프로세스 : JavaScript 📌 문제 📌 풀이function solution(priorities, location) { let queue = priorities.map((priority, index) => ({ priority, index })); let executionCount = 0; while (queue.length) { let process = queue.shift(); if (queue.some(item => item.priority > process.priority)) { queue.push(process); } else { executionCount++; if (process.index === location) { return executionCount.. 2025. 4. 6. [프로그래머스] 올바른 괄호 : JavaScript 📌 문제 📌 풀이🚫 처음 풀이function solution(s){ return s.startsWith("(") && s.endsWith(")") && s.length % 2 === 0}'(' 로 시작하고, ')'로 끝나고, 짝지어서 열고 닫아야 한다고 해서 위와 같이 풀었는데 틀렸다ㅜ그 이유는 아래 맞는 풀이에서 설명하겠다 ✅ 맞는 풀이function solution(s) { let count = 0; for (let char of s) { if (char === '(') { count++; } else if (char === ')') { count--; } if (count 처음 풀이.. 2025. 4. 5. [프로그래머스] 모의고사 : JavaScript 📌 문제 📌 풀이function solution(answers) { const obj = {}; const score1 = [1, 2, 3, 4, 5]; const score2 = [2, 1, 2, 3, 2, 4, 2, 5]; const score3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]; answers.forEach((v, i) => { if (v === score1[i % score1.length]) { obj[1] = (obj[1] || 0) + 1; } if (v === score2[i % score2.length]) { obj[2] = (obj[2] || 0) +.. 2025. 3. 29. [프로그래머스] 의상 : JavaScript 📌 문제 📌 풀이function solution(clothes) { const typeCounts = {}; clothes.forEach(item => { const type = item[1]; typeCounts[type] = (typeCounts[type] || 0) + 1; }); let totalCombinations = 1; for (let type in typeCounts) { totalCombinations *= (typeCounts[type] + 1); } return totalCombinations - 1;}typeCounts 에 의상 종류별 개수를 카운트한다각 종류에 대해 의상을 고르지 않는 경우도 고려해야 하므로, 해당 종류의 의상 개수에 1을 .. 2025. 3. 23. 이전 1 2 3 4 ··· 16 다음 728x90 반응형