Leetcode

    [Algorithm] LeetCode 63. Unique Paths 2 (java)

    [Algorithm] LeetCode 63. Unique Paths 2 (java)

    풀이 코드 class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { int m = obstacleGrid.length; int n = obstacleGrid[0].length; if (obstacleGrid[0][0] == 1) return 0; obstacleGrid[0][0] = 1; for (int x = 1; x    사고 과정 https://leetcode.com/problems/unique-paths-ii 앞서 풀었던 Unique Paths 1과 동일하지만, 중간에 장애물이 있다는 조건이 추가되었다.  (이전 1편에서도 중학교 수학 길찾기 문제에서..

    [Algorithm] LeetCode 62. Unique Paths (java)

    [Algorithm] LeetCode 62. Unique Paths (java)

    풀이 코드 import java.util.Arrays;class Solution { public int uniquePaths(int m, int n) { int[][] memo = new int[m][n]; for(int[] arr : memo) { Arrays.fill(arr, 1); } for(int col = 1; col   사고 과정 https://leetcode.com/problems/unique-paths/description/ 오늘은 midium 난이도 치고 상당히 쉬우면서 DP의 진가를 엿볼 수 있는 문제로 풀어보았다.  단순히 점화식만 만들면 되었던 문제..  시작하기 앞서, 다음 constraint에 주목하면 좋..

    [Algorithm] Leetcode 200. Number of Islands (java)

    풀이 코드 class Solution { private static final int[][] DIRECTION = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; public int numIslands(char[][] grid) { int m = grid.length; int n = grid[0].length; int ans = 0; for (int y = 0; y = grid.length || x = grid[0].length) return; if(grid[y][x] == '1'){ grid[y][x] = '0'; for(int[] ..

    [Algorithm] Leetcode 1. Two Sum(java)

    [Algorithm] Leetcode 1. Two Sum(java)

    풀이 코드class Solution { public int[] twoSum(int[] nums, int target) { Map map = new HashMap(); for (int i = 0; i   사고 과정오늘은 무려 LeetCode 1번 문제..투썸! https://leetcode.com/problems/two-sum/ LeetCode - The World's Leading Online Programming Learning PlatformLevel up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next..

    [A100C_day 2] Leetcode 88. Merge Sorted Array (java)

    [A100C_day 2] Leetcode 88. Merge Sorted Array (java)

    문제 링크 https://leetcode.com/problems/merge-sorted-array/ LeetCode - The World's Leading Online Programming Learning Platform 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 문제 분석 1. 주어진 인자는 sorted array인 nums1, nums2 그리고 각각이 이들의 요소 개수인 m, n 2. 앞으로 보나 뒤로 보나 two pointer로 풀면 될 것 같다! 3. 중요한 점은 새..

    [A100C_day 1] Leetcode 704. Binary Search (java)

    [A100C_day 1] Leetcode 704. Binary Search (java)

    문제 링크 https://leetcode.com/problems/binary-search/ LeetCode - The World's Leading Online Programming Learning Platform 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 문제 분석 1. 먼저 주어진 nums는 sorted array -> 이제 기본적으로 Binary Search가 가장 먼저 떠올라야 한다. 2. 1