diff --git a/combination-sum/minji-go.java b/combination-sum/minji-go.java new file mode 100644 index 000000000..ab895923a --- /dev/null +++ b/combination-sum/minji-go.java @@ -0,0 +1,33 @@ +/* + Problem: https://leetcode.com/problems/combination-sum/ + Description: return a list of all unique combinations of candidates where the chosen numbers sum to target + Concept: Array, Backtracking + Time Complexity: O(Nⁿ), Runtime 2ms + Space Complexity: O(N), Memory 44.88MB + + - Time Complexity, Space Complexity를 어떻게 계산해야할지 어렵네요 :( +*/ +class Solution { + public List> answer = new ArrayList<>(); + + public List> combinationSum(int[] candidates, int target) { + Arrays.sort(candidates); + findCombination(candidates, target, new ArrayList<>(), 0); + return answer; + } + + public void findCombination(int[] candidates, int target, List combination, int idx) { + if(target == 0) { + answer.add(new ArrayList<>(combination)); + return; + } + + for(int i=idx; i target) break; + + combination.add(candidates[i]); + findCombination(candidates, target-candidates[i], combination, i); + combination.remove(combination.size()-1); + } + } +} diff --git a/construct-binary-tree-from-preorder-and-inorder-traversal/minji-go.java b/construct-binary-tree-from-preorder-and-inorder-traversal/minji-go.java index 1f7f3a769..bb5efde92 100644 --- a/construct-binary-tree-from-preorder-and-inorder-traversal/minji-go.java +++ b/construct-binary-tree-from-preorder-and-inorder-traversal/minji-go.java @@ -2,7 +2,7 @@ Problem: https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ Description: Given two integer arrays preorder and inorder, construct and return the binary tree. Concept: Array, Hash Table, Divide and Conquer, Tree, Binary Tree - Time Complexity: O(NM), Runtime 2ms + Time Complexity: O(N²), Runtime 2ms Space Complexity: O(N), Memory 45.02MB */ import java.util.HashMap; diff --git a/maximum-subarray/minji-go.java b/maximum-subarray/minji-go.java new file mode 100644 index 000000000..617d215a7 --- /dev/null +++ b/maximum-subarray/minji-go.java @@ -0,0 +1,18 @@ +/* + Problem: https://leetcode.com/problems/maximum-subarray/ + Description: return the largest sum of the subarray, contiguous non-empty sequence of elements within an array. + Concept: Array, Divide and Conquer, Dynamic Programming + Time Complexity: O(N), Runtime 1ms + Space Complexity: O(1), Memory 57.02MB +*/ +class Solution { + public int maxSubArray(int[] nums) { + int max = nums[0]; + int sum = nums[0]; + for(int i=1; i 0 ? n : n + 2 * (long) Math.pow(2,31); //= Integer.toUnsignedLong() + + int reversedNum = 0; + for(int i=31; i>=0; i--){ + if(unsignedNum % 2 == 1) reversedNum += (long) Math.pow(2,i); //= (1< numIndex = new HashMap<>(); + for(int secondIndex=0; secondIndex