๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

๐Ÿ”‘ ์•Œ๊ณ ๋ฆฌ์ฆ˜65

[LeetCode] 125_Palindrome ์ฒ˜์Œ ํ’€์ด ๋ฌธ์ œ ๋งํฌ 125_Valid Palindrome โ˜๏ธŽ ์ฒ˜์Œ ํ’€์ด var isPalindrome = function (s) { s = s.toUpperCase(); let ans = []; for (let i = 0; i = 'A' && s[i] = '0' && s[i] 2021. 12. 7.
[LeetCode] 28_ImplementstrStr -JavaScript ๋ฌธ์ œ ๋งํฌ : 28_ImplementstrStr string ๋ฌธ์ œ haystack๊ณผ needle์ด ์ฃผ์–ด์กŒ์„ ๋•Œ needle์ด haystack์— ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ์žˆ์œผ๋ฉด ํ•ด๋‹น idx๋ฅผ ์—†์œผ๋ฉด -1์„ returnํ•œ๋‹ค. โ˜๏ธŽ ์ฒ˜์Œ ํ’€์ด var strStr = function (haystack, needle) { let needleLen = needle.length; for (let i = 0; i < haystack.length; i++) { if (haystack[i] === needle[0]) { if (haystack.substring(i, i + needleLen) === needle) return i; } } } haystack์˜ ๊ฐœ์ˆ˜๋งŒํผ for๋ฌธ์„ ๋Œ๋ฉฐ ๊ทธ ์ฒซ ๊ธ€์ž๊ฐ€ ๊ฐ™๋‹ค๋ฉด needle์˜๊ธธ์ด๋งŒํ‹ˆ์˜ ๋ฌธ.. 2021. 12. 2.
[LeetCode] 64 _ minimumPathSum ๋‚˜์˜ ํ’€์ด var minPathSum = function (grid) { let mLen = grid.length; let nLen = grid[0].length; const DP = [...new Array(mLen)].map(() => []); DP[0][0] = grid[0][0]; for (let i = 0; i < mLen; i++) { for (let j = 0; j < nLen; j++) { if (i === 0 && j === 0) DP[i][j] = grid[i][j]; // ์šฐ์ธก ๋ฐฉํ–ฅ else if (j === 0) DP[i][j] = grid[i][j] + DP[i - 1][j]; // ํ•˜๋‹จ ๋ฐฉํ–ฅ else if (i === 0) DP[i][j] = grid[i][j] + DP[i][j.. 2021. 11. 23.
[LeetCode] 746 Min Cost Climbing Stairs-javascript ๋‚˜์˜ ํ’€์ด var minCostClimbingStairs = function(cost) { const goalStair = cost.length let DP=[] DP[0] = 0; DP[1] = 0; DP[2] = Math.min(cost[0],cost[1]) for (let i=3 ; i 2021. 11. 20.
[๋ฐฑ์ค€] node.js/ 2606_๋ฐ”์ด๋Ÿฌ์Šค ์ด๋ฒˆ ๋ฌธ์ œ๋Š” ์‰ฝ์ง€ ์•Š์•˜๋‹ค. dfs๋ฅผ ์ด์šฉํ•ด ํ’€์ดํ•˜๋Š” ๋ฌธ์ œ์˜€๊ณ , ๋‚˜๋Š” dfs์— ์•„์ง ์•ฝํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋” ๋งŽ์ด ๊ณต๋ถ€ํ•ด์•ผ ํ•œ๋‹คใ…. ์ •๋‹ต ํ’€์ด n+1์„ ํ•˜๋Š” ์ด์œ ๋Š” ์ธ๋ฑ์Šค์™€ ์ˆ˜๋ฅผ ๋งž์ถฐ์ฃผ๊ธฐ ์œ„ํ•ด์„œ! ( 0 idx์˜ ๊ฐ’์€ ์“ฐ์ง€ ์•Š๋Š”๋‹ค๊ณ  ๋ณด๋ฉด ๋œ๋‹ค.) const fs = require('fs'); let input = (fs.readFileSync('./dev/stdin') + '').toString().trim().split('\n'); let n = Number(input.shift()); let m = Number(input.shift()); let graph = [...new Array(n + 1)].map(() => []); let visited = new Array(n + 1).fill(false); let.. 2021. 11. 7.
[๋ฐฑ์ค€] node.js/ 1463_1๋กœ ๋งŒ๋“ค๊ธฐ ๋ฌธ์ œ๋ฅผ ๋ณด์ž๋งˆ์ž ๋Š๋‚Œ์ด ์™”๋‹ค. ์•„ ์ด๊ฑฐ.. ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ํ•„์š”ํ•˜๋‹ค!!!!! ์ฒ˜์Œ์—๋Š” 3๋ถ€ํ„ฐ ๋‚˜๋ˆ„๊ณ , 2๋ถ€ํ„ฐ๋‚˜๋ˆ‹๊ณ  -1 ํ•˜๋ฉด ๋˜์ง€ ๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋Š”๋ฐ ์ฒœ๋งŒ์˜ ๋ง์”€~ ํžŒํŠธ์— ๋–กํ•˜๋‹ˆ ๋‚˜์™€ ์žˆ๋Š” ๊ฐ€๋ฅด์นจ์„ ๋ณด๊ณ  ๋ฐ”๋กœ ๋Œ๋ ธ๋‹ค. ์ฐธ๊ณ  ํ’€์ด const fs = require('fs'); let n = (fs.readFileSync('./dev/stdin') + '').toString().trim(); n = Number(n); const DP = new Array(n + 1).fill(0); for (let i = 2; i 2021. 10. 27.
๋ฐฑ์ค€] node.js/ 1448_ ์‚ผ๊ฐํ˜• ๋งŒ๋“ค๊ธฐ ๋‚ด ํ’€์ด (์‹œ๊ฐ„์ดˆ๊ณผ) const fs = require('fs'); let input = (fs.readFileSync('./dev/stdin') + '').toString().trim().split('\n'); const n = +input.shift(); let sumArr = []; input = input.map((line) => parseInt(line)); input.sort((a, b) => parseInt(b) - parseInt(a)); const checkTri = (a, b, c) => { return a < b + c; }; for (let i = 0; i < n - 2; i++) { if (checkTri(input[i], input[i + 1], input[i + 2])) { a.. 2021. 10. 23.
[๋ฐฑ์ค€] node.js/ 1748_ ์ˆ˜ ์ด์–ด์“ฐ๊ธฐ(1) ๋‚ดํ’€์ด const fs = require('fs'); let input = (fs.readFileSync('./dev/stdin') + '').toString().trim(); const lenInput = input.length; let cnt = 0; // 1 2 3 // 10-1 100-10 + 120-(100-1) for (let i = 1; i 2021. 10. 22.
[๋ฐฑ์ค€] node.js/ 15650 N๊ณผM(2) ๋‚ด ํ’€์ด const fs = require('fs'); let [n, m] = (fs.readFileSync('./dev/stdin') + '').toString().trim().split(' '); let visit = new Array(parseInt(n)).fill(false); n = parseInt(n); m = parseInt(m); let ans = []; const back = (d, n, m, idx) => { if (d === m) { console.log(...ans); return; } for (let i = idx; i < n; i++) { if (visit[i]) continue; visit[i] = true; ans.push(i + 1); back(d + 1, n, m, i);.. 2021. 10. 21.
๋ฐ˜์‘ํ˜•