diff --git a/coin-change/minji-go.java b/coin-change/minji-go.java new file mode 100644 index 000000000..527a23d8e --- /dev/null +++ b/coin-change/minji-go.java @@ -0,0 +1,23 @@ +/* + Problem: https://leetcode.com/problems/coin-change/ + Description: return the fewest number of coins that you need to make up that amount + Concept: Array, Dynamic Programming, Breadth-First Search + Time Complexity: O(NM), Runtime 15ms - M is the amount + Space Complexity: O(M), Memory 44.28MB +*/ +class Solution { + public int coinChange(int[] coins, int amount) { + int[] dp = new int[amount+1]; + Arrays.fill(dp, amount+1); + dp[0]=0; + + for(int i=1; i<=amount; i++){ + for(int coin : coins){ + if(i >= coin) { + dp[i] = Math.min(dp[i], dp[i-coin] +1); + } + } + } + return dp[amount]>amount? -1: dp[amount]; + } +} diff --git a/combination-sum/minji-go.java b/combination-sum/minji-go.java index ab895923a..fac01b813 100644 --- a/combination-sum/minji-go.java +++ b/combination-sum/minji-go.java @@ -2,10 +2,8 @@ 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를 어떻게 계산해야할지 어렵네요 :( + Time Complexity: O(Nᵀ), Runtime 2ms + Space Complexity: O(T), Memory 44.88MB */ class Solution { public List> answer = new ArrayList<>(); diff --git a/merge-two-sorted-lists/minji-go.java b/merge-two-sorted-lists/minji-go.java new file mode 100644 index 000000000..d70eac76f --- /dev/null +++ b/merge-two-sorted-lists/minji-go.java @@ -0,0 +1,36 @@ +/* + Problem: https://leetcode.com/problems/merge-two-sorted-lists/ + Description: return the head of the merged linked list of two sorted linked lists + Concept: Linked List, Recursion + Time Complexity: O(N+M), Runtime 0ms + Space Complexity: O(N+M), Memory 42.74MB +*/ + +/** + * Definition for singly-linked list. + * public class ListNode { + * int val; + * ListNode next; + * ListNode() {} + * ListNode(int val) { this.val = val; } + * ListNode(int val, ListNode next) { this.val = val; this.next = next; } + * } + */ +class Solution { + public ListNode mergeTwoLists(ListNode list1, ListNode list2) { + + ListNode head = new ListNode(0); + ListNode tail = head; + + while(list1 != null || list2 != null) { + if (list2 == null || (list1 != null && list1.val <= list2.val)) { + tail = tail.next = new ListNode(list1.val); + list1 = list1.next; + } else { + tail = tail.next = new ListNode(list2.val); + list2 = list2.next; + } + } + return head.next; + } +} diff --git a/missing-number/minji-go.java b/missing-number/minji-go.java new file mode 100644 index 000000000..61cc2894f --- /dev/null +++ b/missing-number/minji-go.java @@ -0,0 +1,19 @@ +/* + Problem: https://leetcode.com/problems/missing-number/ + Description: return the only number in the range that is missing from the array. + Concept: Array, Hash Table, Math, Binary Search, Bit Manipulation, Sorting + Time Complexity: O(N), Runtime 0ms + Space Complexity: O(1), Memory 45.71MB +*/ +class Solution { + public int missingNumber(int[] nums) { + int n = nums.length; + int missing = n; + + for(int i=0; i=0 && rightm-1||nc>n-1||visited[nr][nc]) continue; + if(board[nr][nc]!=word.charAt(i)) continue; + if(wordExists(nr, nc, i+1)) return true; + } + visited[cr][cc] = false; + + return false; + } +}