헬리'Daily
-
알고리즘문제 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; }
-
알고리즘 문제 2헬리'Daily/꾸준한 알고리즘 2023. 5. 29. 01:35
function findRange(num) { const numStr = num.toString(); let min = 0; let max = 0; let changeIndex = 0; if(numStr[changeIndex] === '1') { changeIndex++; while(changeIndex < numStr.length && (numStr[changeIndex] === '0' || numStr[changeIndex] === '1' )) { changeIndex++; } min = numStr.replaceAll(numStr[changeIndex],'0'); } else { min = numStr.replaceAll(numStr[changeIndex],'1'); } changeIndex = 0..