헬리'Daily
-
[프로그래머스] 코테 (편지)헬리'Daily/꾸준한 알고리즘 2023. 7. 28. 13:42
문제 머쓱이는 할머니께 생신 축하 편지를 쓰려고 합니다. 할머니가 보시기 편하도록 글자 한 자 한 자를 가로 2cm 크기로 적으려고 하며, 편지를 가로로만 적을 때, 축하 문구 message 를 적기 위해 필요한 편지지의 최소 가로길이를 return 하도록 solution 함수를 완성해주세요. 제한사항 공백도 하나의 문자로 취급합니다. 1 ≤ message의 길이 ≤ 50 편지지의 여백은 생각하지 않습니다. message는 영문 알파벳 대소문자, ‘!’, ‘~’ 또는 공백으로만 이루어져 있습니다. 입출력 예 "happy birthday!" 30 "I love you~" 22 나의 풀이 function solution(message) { const charWidth = 2; // 각 글자의 가로 크기 (2..
-
알고리즘문제 5헬리'Daily/꾸준한 알고리즘 2023. 5. 29. 01:38
너무어려워이거....완젼히 다 맞지는못했다... function minimumTreePath(n, edges, visitNodes) { const INF = 1e9; const dist = Array(n).fill().map(()=> Array(n).fill(INF)); const visit = visitNodes.map(v => v-1); edges.forEach(([u, v]) =>{ dist[u-1][v-1] =1; dist[v-1][u-1] =1; }); for(let k=0; k < n; k++) for(let i=0; i
-
알고리즘문제 4헬리'Daily/꾸준한 알고리즘 2023. 5. 29. 01:37
function longestChain(words) { const dp = {}; words.sort((a,b)=>a.length - b.length); let max = 0; for(const word of words){ let longest = 0; for(let i =0; i< word.length; i++){ const sub = word.slice(0,i) + word.slice(i+1); longest = Math.max(longest, (dp[sub] || 0)+1); } dp[word]=longest; max = Math.max(max, longest); } return max; }