This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://oj.leetcode.com/problems/remove-nth-node-from-end-of-list/ | |
Given a linked list, remove the nth node from the end of list and return its head. | |
For example, | |
Given linked list: 1->2->3->4->5, and n = 2. | |
After removing the second node from the end, the linked list becomes 1->2->3->5. | |
Note: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://oj.leetcode.com/problems/same-tree/ | |
/** | |
* Definition for binary tree | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
* }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://oj.leetcode.com/problems/reverse-nodes-in-k-group/ | |
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. | |
If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is. | |
You may not alter the values in the nodes, only nodes itself may be changed. | |
Only constant memory is allowed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://oj.leetcode.com/problems/minimum-path-sum/ | |
/* | |
초기 접근: | |
전수조사를 해야하는가->그렇다. | |
어떻게 가지치기 할 것인가-> dp 적용 | |
base case 설정: | |
if left == m-1, down == n-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ | |
/** | |
* Definition for binary tree | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
* }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://oj.leetcode.com/problems/jump-game-ii/ | |
/* | |
O(n^2) solution: 각 ele에 도달하는 mininum jump 수를 계산 | |
class Solution { | |
public: | |
int jump(int A[], int n) { | |
int* B = new int[n]; | |
int minJump = INT_MIN; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://oj.leetcode.com/problems/swap-nodes-in-pairs/ | |
Given a linked list, swap every two adjacent nodes and return its head. | |
For example, | |
Given 1->2->3->4, you should return the list as 2->1->4->3. | |
Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed. | |
/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://oj.leetcode.com/problems/maximum-subarray/ | |
Find the contiguous subarray within an array (containing at least one number) which has the largest sum. | |
For example, given the array [−2,1,−3,4,−1,2,1,−5,4], | |
the contiguous subarray [4,−1,2,1] has the largest sum = 6. | |
class Solution { | |
public: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://oj.leetcode.com/problems/gray-code/ | |
The gray code is a binary numeral system where two successive values differ in only one bit. | |
Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. | |
For example, given n = 2, return [0,1,3,2]. Its gray code sequence is: | |
00 - 0 | |
01 - 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://oj.leetcode.com/problems/binary-tree-zigzag-level-order-traversal/ | |
/* | |
BFS를 응용해서, 자료구조를 queue 대신에 deque 또는 vector를 이용, 한번은 front에서부터, 한번은 back 에서부터 pop 하면 될 듯 | |
Time complexity : O(n) | |
순회순서는 | |
root(->) | |
1 level depth(<-) | |
2 level depth(->) |