목록전체 글 (709)
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를 적용한다. 로봇은 오른쪽 또는 아래로 가기 때문에 순회를 하면서 점화식을 적용한 값을 배열에 저장..
https://leetcode.com/problems/jump-game-ii/ Jump Game 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 알고리즘 사용. dp 배열을 nums의 length 만큼 선언하고, Infinity로 초기화 한다. 시작은 0번째 인덱스부터 시작하기 때문에 dp[0] = 0으로 저장하고 for문을 시작한다. nums 배열을 순회. nums[i]는 점프할 수 있는 최대 거리를 나타내기 때문에 이중 for문으로 끝까지 갈 수..
https://leetcode.com/problems/min-cost-climbing-stairs/ Min Cost Climbing Stairs - 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 알고리즘 사용. cost의 길이를 나타내는 length. dp를 length의 길이만큼 할당하고 0으로 초기화. 계단은 1칸 또는 2칸 오를 수 있다. 그렇기 때문에 dp[0] = cost[0], dp[1] = cost[0] + cost[1] 과 cost[1] 중 ..
https://programmers.co.kr/learn/courses/30/lessons/72414 코딩테스트 연습 - 광고 삽입 시간을 나타내는 HH, H1, H2의 범위는 00~99, 분을 나타내는 MM, M1, M2의 범위는 00~59, 초를 나타내는 SS, S1, S2의 범위는 00~59까지 사용됩니다. 잘못된 시각은 입력으로 주어지지 않습니다. (예: 04:60:24, 11 programmers.co.kr 누적합 관련 문제. IMOS 알고리즘을 사용했다. -변수 및 함수 설명- time: 정답을 구한 시간(number) sum: 광고 누적 시간의 최대값 imos배열 : 광고 누적합을 구하기 위한 배열 calculateSecond 함수: 들어온 시,분,초를 초 단위로 변환해 모두 더해 값을 리턴..
https://programmers.co.kr/learn/courses/30/lessons/92344 코딩테스트 연습 - 파괴되지 않은 건물 [[5,5,5,5,5],[5,5,5,5,5],[5,5,5,5,5],[5,5,5,5,5]] [[1,0,0,3,4,4],[1,2,0,2,3,2],[2,1,0,3,1,2],[1,0,1,3,3,1]] 10 [[1,2,3],[4,5,6],[7,8,9]] [[1,1,1,2,2,4],[1,0,0,1,1,2],[2,2,0,2,0,100]] 6 programmers.co.kr 새로운 알고리즘을 배웠다. 누적합을 효율적으로 처리할 수 있는 알고리즘이다. IMOS 알고리즘이라고, 아래 블로그에서 설명이 자세하게 잘 나와있어서 참고해서 풀 수 있었다. https://nicotina04...