Computer Science/Algorithm (8) 썸네일형 리스트형 [LeetCode] 198. House Robber (Java) 문제 https://leetcode.com/problems/house-robber/ House Robber - 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 풀이 class Solution { public int rob(int[] nums) { if(nums.length ==0) return 0; int dp[] = new int[nums.length+1]; dp[0] = 0; dp[1] = nums[0]; for(int i=1; i [LeetCode] 226. Invert Binary Tree (Java) 문제 https://leetcode.com/problems/invert-binary-tree/ Invert Binary Tree - 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 풀이 /** * https://leetcode.com/problems/invert-binary-tree/ * Level: Easy */ /** * Definition for a binary tree node. * public class TreeNode { * int val; * Tree.. [LeetCode] 617. Merge Two Binary Trees 두 개의 이진트리 병합 (Java) 문제 https://leetcode.com/problems/merge-two-binary-trees/ Merge Two Binary 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 풀이 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) .. [LeetCode] 189. Rotate Array 1차원 배열 이동 (Java) 문제 https://leetcode.com/problems/rotate-array/ Rotate Array - 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 풀이 class Solution { public void rotate(int[] nums, int k) { // Make sure that k is less than the length of the arra k = k % nums.length; // First, Reverse all the numbers r.. [LeetCode] 746. Min Cost Climbing Stairs 최소비용으로 계단오르기 알고리즘 문제풀이 (Java) 문제 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 풀이 // 탐욕 알고리즘 public static int minCostClimbingStairs(int[] cost) { for (int i=2; i=0; i--){ current = cost[i] + Math.min(case1, case2); // 한 칸 멀리 있.. 탐욕알고리즘(Greedy Algorithm), 분할-정복 알고리즘(Divide-and-conquer algorithm), 동적계획법(Dynamic Programming) 탐욕 알고리즘 여러 경우 중 하나를 결정해야 할 때마다 그 순간에 최적이라고 생각되는 것을 선택해 나가는 방식으로 진행하여 최적해에 도달 항상 최적의 해를 도출하지 않지만 속도가 빠름 거의 메모리를 사용하지 않음 분할 정복 알고리즘 주어진 문제를 작은 사례로 나누고 각각의 작은 문제들을 해결하여 정복 하는 방법 항상 최적의 해를 도출하나 탐욕 알고리즘보다 속도가 느림 재귀 호출(recursive calls)을 저장하기 위해 메모리 사용 동적 계획법 분할 정복 알고리즘과 같으나 계산을 반복하는 것이 아니라 각각의 하위문제의 답을 저장해서 최적화한다는 점이 다름 메모이제이션(Memoization)을 위한 많은 메모리 사용 컴퓨터 프로그램이 동일한 계산을 반복해야 할 때, 이전에 계산한 값을 메모리에 저장함으.. [LeetCode] 167. Two Sum II - Input array is sorted 알고리즘 문제풀이 (JAVA) 문제 https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/submissions/ Two Sum II - Input array is sorted - 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 풀이 class Solution { public int[] twoSum(int[] numbers, int target) { int n = numbers.length,i=0,j=n-1; while(i target).. [LeetCode] 118. Pascal's Triangle 파스칼 삼각형 알고리즘 문제풀이 (Java) 문제 https://leetcode.com/problems/pascals-triangle/ Pascal's Triangle - 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 풀이 public static List generate(int numRows) { List triangle = new ArrayList(); // 사용자가 0개 열을 요청할 때, 빈 배열을 리턴한다. if(numRows==0) return triangle; // return [ ]; // 첫.. 이전 1 다음