목록js (166)
N
npx create-next-app yarn create-next-app # using typescript npx create-next-app --typescript yarn create-next-app --typescript next.js 앱 생성을 위한 커맨드. 현재 폴더에 next.js 프로젝트를 만들고 싶다면 npx create-next-app . yarn create-next-app . # using typescript npx create-next-app --typescript . yarn create-next-app --typescript .
https://leetcode.com/problems/di-string-match/ DI String Match - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 투포인터 알고리즘 적용. 답을 리턴할 배열 answer을 선언. front와 back을 이용해 답을 찾을 것이다. front = 0, back = s.length으로 선언한 후 for문 진행. 만약 현재 문자가 "I"라면 front++를 answer에 push. 그렇지 않고 "D"라면 back--를 a..
https://leetcode.com/problems/lemonade-change/ Lemonade Change - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 그리디 알고리즘. 5, 10, 20달러를 받았을 때 거스름돈을 남길 수 있는지 확인하면 된다. money라는 이름으로 3의 길이만큼 선언. 0의 인덱스부터 5, 10, 20 달러를 가진다. for문으로 bills를 순회. 만약 5달러를 받았다면 거스름돈은 없기 때문에 money[0]++. 10달러를 받..
https://leetcode.com/problems/can-place-flowers/ Can Place Flowers - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 그리디 알고리즘. n개의 꽃을 flowerbed에 심어야 하는데, 근접한 위치에 꽃이 없어야 한다. for문을 이용해 flowerbed를 순회. 만약 현재 n이 0이라면 모두 심었기 때문에 바로 true를 리턴한다. 그렇지 않고 n이 남아있다면 최대한 꽃을 심어본다. 맨 앞에서부터 꽃을 심으면 ..
https://leetcode.com/problems/assign-cookies/ Assign Cookies - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 그리드 알고리즘 주어진 두 배열을 오름차순으로 정렬하여 시작. 이중 for문을 적용. sIndex를 0으로 시작하여, for문을 돌면서 sIndex가 s.length와 같아지면 바로 종료할 수 있도록 한다. g와 s를 순회하면서 g[i] a - b); s.sort((a, b) => a - b); for(l..
https://leetcode.com/problems/decode-ways/ Decode Ways - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com const numDecodings = (s) => { const length = s.length; const dp = Array(length + 1).fill(0); if(s[0] === "0"){ return 0; } dp[length] = 1; dp[length - 1] = parseInt(s[length - 1..
https://leetcode.com/problems/unique-paths-ii/ Unique Paths II - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com DP 알고리즘. Unique Path 문제에서 장애물이 추가된 문제다. m x n 크기로 DP 배열을 선언하여 0으로 초기화한다. 만약 obstacleGrid[0][0]이 1이라면 출발점이 장애물로 막혀있고, 더 이상 진행할 수 없다는 뜻이된다. 그렇다면 0을 바로 리턴하여 종료한다. 그렇지 않다면 이..
https://leetcode.com/problems/unique-paths/ Unique Paths - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com DP 알고리즘. m x n 크기의 배열을 선언하고 0으로 초기화한다. [0, 0] 좌표에서 [m - 1, n - 1] 좌표까지 갈 수 있는 방법을 모두 구하는데, [0, 0]은 1로 시작하고 이중 for문으로 DP를 적용한다. 로봇은 오른쪽 또는 아래로 가기 때문에 순회를 하면서 점화식을 적용한 값을 배열에 저장..