알고리즘/Leetcode
-
LeetCode_931. Minimum Falling Path Sum알고리즘/Leetcode 2020. 12. 22. 00:22
leetcode.com/problems/minimum-falling-path-sum/ Minimum Falling Path Sum - 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 Solution1. 최종 목적지에서부터 역으로 최소가 되는 값을 찾아 table(r,c)에 기록하는 방법으로 접근 (지금 생각 하니 최초 출발지에서 시작 하든 동일하네...;;) row = 2 : (2,0)에서의 최소값은 7, (2,2)에서의 최소값은 8, (2,2)에서의 최소값은 9..
-
LeetCode_96. Unique Binary Search Trees알고리즘/Leetcode 2020. 12. 21. 23:54
leetcode.com/problems/unique-binary-search-trees/ Unique Binary Search Trees - 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 Solution1. Input N에 대해서 1~N에 대해서 루트일 경우는, root node가 1일 경우 : [왼쪽 자식] null F(0), [오른쪽 자식] N-1 case --> F(N-1) root node가 2일 경우 : [왼쪽 자식] F(1), [오른쪽 자식] N-2 ..
-
LeetCode_64. Minimum Path Sum알고리즘/Leetcode 2020. 12. 21. 22:23
leetcode.com/problems/minimum-path-sum/ Minimum Path Sum - 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 Solution1. M x N 사이즈의 table을 이용( all zero), (r,c) 칸으로 이동할수 있는 경우는 바로 위에칸(r-1,c)에서 아래로 이동하거나 왼쪽 칸(r,c-1)에서 오른쪽으로이동하는 경우만 존재 함, 따라서 (r,c)까지 이동 가능한 경우에서 최소값을 선택 table[r][c] = min..
-
LeetCode_63. Unique Paths II알고리즘/Leetcode 2020. 12. 21. 22:11
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 Solution1. 2020/12/21 - [알고리즘/Leetcode] - LeetCode_62. Unique Paths 에서 장애물이 추가된 문제 이전과 동일하게 M x N 사이즈의 table을 이용하고 (r,c) 칸으로 이동할수 있는 경우는 아래와 같이 표현 가능하다. table[r][c] = table[r-1]..
-
LeetCode_62. Unique Paths알고리즘/Leetcode 2020. 12. 21. 22:03
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 Solution1. M x N 사이즈의 table을 이용, (r,c) 칸으로 이동할수 있는 경우는 바로 위에칸(r-1,c)에서 아래로 이동하거나 왼쪽 칸(r,c-1)에서 오른쪽으로이동하는 경우만 존재 함, 따라서 (r,c)까지 이동 할수 있는 경우의 수는 아래와 같이 표현 가능하다. table[r][c] = table[r-1]..
-
LeetCode_486. Predict the Winner알고리즘/Leetcode 2020. 12. 18. 13:45
leetcode.com/problems/predict-the-winner/ Predict the Winner - 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 Solution1. 2차원 배열을 이용하여 [start, end] 구간에서의 점수 차를 저장 즉, DP[start][end] >= 0 : win 을 의미하고 DP[start][end] < 0 : Lose 를 의미 if start == end : dp[start][end] = nums[start] else ..
-
LeetCode_1140.Stone Game II알고리즘/Leetcode 2020. 12. 18. 11:27
leetcode.com/problems/stone-game-ii/ Stone 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 Solution1. class Solution: def stoneGameII(self, a: List[int]) -> int: @lru_cache(maxsize=None) def minimax(idx, M, isAlex): if idx > len(piles) : return 0 if isAlex: # Alice`s Turn..