diff --git a/coin-change/haung921209.md b/coin-change/haung921209.md new file mode 100644 index 000000000..891d25ad6 --- /dev/null +++ b/coin-change/haung921209.md @@ -0,0 +1,76 @@ +# 연관 링크 +- [문제 풀이 스케줄](https://github.com/orgs/DaleStudy/projects/6/views/5) +- [답안 코드 제출법](https://github.com/DaleStudy/leetcode-study/wiki/%EB%8B%B5%EC%95%88-%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C) + +# Problem +- 문제 링크 : https://leetcode.com/problems/coin-change/description/ +- 문제 이름 : Coin Change +- 문제 번호 : 322 +- 난이도 : Medium +- 카테고리 : BFS + +# 문제 설명 + + +# 아이디어 +- bfs + +# ✅ 코드 (Solution) +``` +class Solution { +public: + int coinChange(vector& coins, int amount) { + if(amount==0){ + return 0; + } + vector res(amount + 1, -1); + queue q; + for (auto coin : coins) { + if (coin > amount) { + continue; + } + if (coin == amount) { + return 1; + } + res[coin] = 1; + q.push(coin); + } + while (q.size()) { + int curCoin = q.front(); + q.pop(); + int nextCount = res[curCoin] + 1; + for (auto coin : coins) { + int nextCoin = curCoin + coin; + if (nextCoin > amount) { + continue; + } + if (res[nextCoin] != -1) { + continue; + } + if (nextCoin == amount) { + return nextCount; + } + res[nextCoin] = nextCount; + q.push(nextCoin); + } + } + return res[amount]; + } +}; + +``` +# 🔍 코드 설명 + + +# 최적화 포인트 (Optimality Discussion) +• 최적화한 이유와 원리 +• 더 줄일 수 있는 여지는 있는가? +• 기존 방법 대비 얼마나 효율적이었는지 + +# 🧪 테스트 & 엣지 케이스 + +# 📚 관련 지식 복습 + +# 🔁 회고 + + diff --git a/find-minimum-in-rotated-sorted-array/haung921209.md b/find-minimum-in-rotated-sorted-array/haung921209.md new file mode 100644 index 000000000..a62c7dde1 --- /dev/null +++ b/find-minimum-in-rotated-sorted-array/haung921209.md @@ -0,0 +1,81 @@ +# 연관 링크 +- [문제 풀이 스케줄](https://github.com/orgs/DaleStudy/projects/6/views/5) +- [답안 코드 제출법](https://github.com/DaleStudy/leetcode-study/wiki/%EB%8B%B5%EC%95%88-%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C) + +# Problem +- 문제 링크 : +- 문제 이름 : +- 문제 번호 : +- 난이도 : +- 카테고리 : + +# 문제 설명 + + +# 아이디어 +- 어떤 방법으로 접근했는지 서술 +- 포스 vs 최적화 아이디어 차이 등 +- 잡도에 대한 고려 + +# ✅ 코드 (Solution) +## Linear Search +```cpp +class Solution { +public: + int findMin(vector& nums) { + int res = nums[0]; + for(int i=1;i& nums) { + int left = 0, right = nums.size() - 1; + + while (left < right) { + int mid = left + (right - left) / 2; + + if (nums[mid] > nums[right]) { + left = mid + 1; + } else { + right = mid; + } + } + + return nums[left]; + } +}; +``` + +- O(log n) +- The Exact Solution they want...! + +# 🔍 코드 설명 + + +# 최적화 포인트 (Optimality Discussion) +- Binary Search 를 통한 O(log n) 처리 + - Binary Search에 대한 연습이 필요하다 + + +# 🧪 테스트 & 엣지 케이스 + +# 📚 관련 지식 복습 +- Binary Search에 대한 연습이 필요하다 + + +# 🔁 회고 + + diff --git a/maximum-depth-of-binary-tree/haung921209.md b/maximum-depth-of-binary-tree/haung921209.md new file mode 100644 index 000000000..5783a6a02 --- /dev/null +++ b/maximum-depth-of-binary-tree/haung921209.md @@ -0,0 +1,57 @@ +# 연관 링크 +- [문제 풀이 스케줄](https://github.com/orgs/DaleStudy/projects/6/views/5) +- [답안 코드 제출법](https://github.com/DaleStudy/leetcode-study/wiki/%EB%8B%B5%EC%95%88-%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C) + +# Problem +- 문제 링크 : https://leetcode.com/problems/maximum-depth-of-binary-tree/description/ +- 문제 이름 : Maximum Depth of Binary Tree +- 문제 번호 : 104 +- 난이도 : easy +- 카테고리 : + +# 문제 설명 + + +# 아이디어 +- 재귀 + +# ✅ 코드 (Solution) + +```cpp +/** + * Definition for a binary tree node. + * struct TreeNode { + * int val; + * TreeNode *left; + * TreeNode *right; + * TreeNode() : val(0), left(nullptr), right(nullptr) {} + * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} + * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} + * }; + */ +class Solution { +public: + int maxDepth(TreeNode* root) { + if(!root) + return 0; + return 1 + max(maxDepth(root->left), maxDepth(root->right)); + } +}; +``` + + +# 🔍 코드 설명 + + +# 최적화 포인트 (Optimality Discussion) +• 최적화한 이유와 원리 +• 더 줄일 수 있는 여지는 있는가? +• 기존 방법 대비 얼마나 효율적이었는지 + +# 🧪 테스트 & 엣지 케이스 + +# 📚 관련 지식 복습 + +# 🔁 회고 + + diff --git a/merge-two-sorted-lists/haung921209.md b/merge-two-sorted-lists/haung921209.md new file mode 100644 index 000000000..a9bc49a89 --- /dev/null +++ b/merge-two-sorted-lists/haung921209.md @@ -0,0 +1,121 @@ +# 연관 링크 +- [문제 풀이 스케줄](https://github.com/orgs/DaleStudy/projects/6/views/5) +- [답안 코드 제출법](https://github.com/DaleStudy/leetcode-study/wiki/%EB%8B%B5%EC%95%88-%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C) + +# Problem +- 문제 링크 : http://leetcode.com/problems/merge-two-sorted-lists/ +- 문제 이름 : Merge Two Sorted Lists +- 문제 번호 : 21 +- 난이도 : easy +- 카테고리 : + +# 문제 설명 + + +# 아이디어 +- 어떤 방법으로 접근했는지 서술 +- 포스 vs 최적화 아이디어 차이 등 +- 잡도에 대한 고려 + +# ✅ 코드 (Solution) +## +```cpp +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode() : val(0), next(nullptr) {} + * ListNode(int x) : val(x), next(nullptr) {} + * ListNode(int x, ListNode *next) : val(x), next(next) {} + * }; + */ +class Solution { +public: + ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) { + auto head = new ListNode(); + auto cur = head; + + while(true){ + if(list1 == nullptr && list2 == nullptr){ + break; + } + if(list1==nullptr){ + cur->next = new ListNode(list2->val); + list2 = list2->next; + cur = cur->next; + continue; + } + + if(list2 == nullptr){ + cur->next = new ListNode(list1->val); + list1 = list1->next; + cur = cur->next; + continue; + } + + if(list1->val > list2->val){ + cur->next = new ListNode(list2->val); + list2 = list2->next; + cur = cur->next; + continue; + }else{ + cur->next = new ListNode(list1->val); + list1 = list1->next; + cur = cur->next; + continue; + } + + + } + + return head->next; + } +}; + +``` + +## 간소화 버전 +```cpp +class Solution { +public: + ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) { + ListNode dummy; + ListNode* cur = &dummy; + + while (list1 && list2) { + if (list1->val < list2->val) { + cur->next = list1; + list1 = list1->next; + } else { + cur->next = list2; + list2 = list2->next; + } + cur = cur->next; + } + + cur->next = list1 ? list1 : list2; + + return dummy.next; + } +}; + +``` + +- 인자 수정 -> 메모리 재활용 + +# 🔍 코드 설명 + + +# 최적화 포인트 (Optimality Discussion) +• 최적화한 이유와 원리 +• 더 줄일 수 있는 여지는 있는가? +• 기존 방법 대비 얼마나 효율적이었는지 + +# 🧪 테스트 & 엣지 케이스 + +# 📚 관련 지식 복습 + +# 🔁 회고 + + diff --git a/word-search/haung921209.md b/word-search/haung921209.md new file mode 100644 index 000000000..8f5e501f1 --- /dev/null +++ b/word-search/haung921209.md @@ -0,0 +1,76 @@ +# 연관 링크 +- [문제 풀이 스케줄](https://github.com/orgs/DaleStudy/projects/6/views/5) +- [답안 코드 제출법](https://github.com/DaleStudy/leetcode-study/wiki/%EB%8B%B5%EC%95%88-%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C) + +# Problem +- 문제 링크 : https://leetcode.com/problems/word-search/submissions/1617585274/ +- 문제 이름 : word search +- 문제 번호 : 79 +- 난이도 : medium +- 카테고리 : + +# 문제 설명 + + +# 아이디어 +- 어떤 방법으로 접근했는지 서술 +- 포스 vs 최적화 아이디어 차이 등 +- 잡도에 대한 고려 + +# ✅ 코드 (Solution) +```cpp + +class Solution { +public: + bool dfs(int i,int j,int count,vector>& board,string word){ + if(word.length()==count) return true; + + if(i<0 || i>=board.size() || j<0 || j>=board[0].size() || board[i][j] != word[count]) + return false; + + + + char temp = board[i][j]; + board[i][j] = ' '; + + + bool ans = dfs(i-1,j,count+1,board,word) || + dfs(i+1,j,count+1,board,word) || + dfs(i,j-1,count+1,board,word) || + dfs(i,j+1,count+1,board,word); + + board[i][j] = temp; + return ans; + } + + bool exist(vector>& board, string word){ + int n = board.size(); + int m = board[0].size(); + + for(int i=0;i