Algorithms

    [Algorithm] LeetCode 670. Maximum Swap (java)

    [Algorithm] LeetCode 670. Maximum Swap (java)

    풀이 코드class Solution { public int maximumSwap(int num) { char[] numArr = Integer.toString(num).toCharArray(); int n = numArr.length; int[] maxRightIndex = new int[n]; maxRightIndex[n - 1] = n - 1; for (int i = n - 2; i >= 0; --i) { maxRightIndex[i] = (numArr[i] > numArr[maxRightIndex[i + 1]]) ? i : maxRightIndex[i + 1]..

    [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] D.P 기본 : Fibonacci

    오늘은 DP 본격적으로 들어가기 전, 기본 중의 기본 FIbonacci로 가자!! 특별히 내놓을 정답 코드는 없다. 여러 방면으로 생각해보고 풀어볼 수 있었던 문제. 문제 : LeetCode 509. Fibonacci Number https://leetcode.com/problems/fibonacci-number/ 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 interview.leetcode.com..

    [A100C day 8] LeetCode 55. Jump Game (java)

    풀이 코드//Greedyclass Solution { public boolean canJump(int[] nums) { int n = nums.length - 1; int reach = 0; for(int i = 0; i   사고 과정 굳이.. 정말 굳이 dp로 풀라면 풀 수는 있는 문제지만, dp보다는 greedy 알고리즘으로 푸는게 훨씬 직관적이고 간편했던 문제.  확실히 문제에 따라서 가장 효과적인 알고리즘을 빠르게 파악 후 적용할 수 있는 능력은 엔지니어에게 중요한 덕목인듯..!! Solution 1. Greedy우선 greedy하게 접근해보면..  각 인덱스를 순회하며 최대로 갈 수 있는 거리를 reach 변수에 초기화해주면서 판단하면 되..

    [Algorithm] LeetCode 647. Palindromic Substrings (java)

    사고 과정 https://leetcode.com/problems/palindromic-substrings/ 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 interview.leetcode.com 기본적인 palindrome 문제. 다만, 해당 String이 회문인지 아닌지 여부를 반환하는 것이 아닌, 해당 문자열 내에서 회문이 될 수 있는 연속된 문자열의 조합 수를 반환해야 했던 문제! Constrai..

    [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..

    [Algorithm] Leetcode 34. Find First and Last Position of Element in Sorted Array (java)

    [Algorithm] Leetcode 34. Find First and Last Position of Element in Sorted Array (java)

    풀이 코드class Solution { public int[] searchRange(int[] nums, int target) { boolean isStart = true; int[] ans = new int[2]; ans[0] = getStartOrEnd(isStart, target, nums); ans[1] = getStartOrEnd(!isStart, target, nums); return ans; } public int getStartOrEnd(boolean isStart, int target, int[] nums){ int left = 0; in..

    [A100C_day 3] Leetcode 79. Word Search (java)

    [A100C_day 3] Leetcode 79. Word Search (java)

    정답 코드 class Solution { private static final int[][] DIRECTION = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; public boolean exist(char[][] board, String word) { int m = board.length; int n = board[0].length; boolean[][] visited = new boolean[m][n]; for(int y = 0; y < m; ++y){ for(int x = 0; x < n; ++x){ if(searchWord(y, x, board, visited, word)) return true; } } return false; } public boolean searchWor..

    [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

    알고리즘 100일 챌린지 - day 0: 챌린지 시작

    챌린지 시작! 이번 챌린지를 통해 얻고 싶은 것은 세 가지 1. 문제를 빠르고 정확히 파악하고 그에 따른 가장 효과적인 해결책을 제시할 수 있는 능력 2. 코드를 논리적, 효율적 짜는 습관 3. 내가 짠 코드를 제 3자가 납득가능토록 글로 풀어낼 수 있는 소통능력 올해부터 같은 개발자를 꿈꾸는 친구와 알고리즘 스터디를 열어 함께 하게 되었는데, 내년(2025년)에는 블로그 차원에서 정식으로 블로그 이름을 건 스터디를 모집하고 싶다!! (블로그도 열심히 키워야지) 지금 하고 있는 서버 관리도 그 때 도움이 될 것 같기도 하고! (지금 만들고 있는 서버는 아직 활용 방안을 못정해서 미정이다..일단 유입될 사람이 많이 필요해..) 모집 시 많관부..