Skip to content

Commit 73bbe73

Browse files
committed
1117
1 parent 6c26c35 commit 73bbe73

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Feel free to submit pull requests, add issues and be a contributer.
4343
| Leetcode | [31. Next Permutation](https://leetcode.com/problems/next-permutation/description/) | [Java](./java/nextPermutation.java) | _O(n)_ | _O(1)_ | Easy | |
4444
| Leetcode | [66. Plus One](https://leetcode.com/problems/plus-one/description/) | [Java](./java/plusOne.java) | _O(n)_ | _O(1)_ | Easy | |
4545
| Leetcode | [88. Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/description/) | [Java](./java/merge.java) | _O(n)_ | _O(1)_ | Easy | |
46+
| Leetcode | [120. Triangle](https://leetcode.com/problems/triangle/description/) | [Java](./java/minimumTotal.java) | _O(m*n)_ | _O(1)_ | Medium | |
4647
| Leetcode | [121. Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/) | [Java](./java/maxProfit.java) | _O(n)_ | _O(1)_ | Easy | |
4748
| Leetcode | [189. Rotate Array](https://leetcode.com/problems/rotate-array/description/) | [Java](./java/rotate.java) | _O(n)_ | _O(1)_ | Easy | |
4849
| Leetcode | [217. Contains Duplicate](https://leetcode.com/problems/contains-duplicate/description/) | [Java](./java/containsDuplicate.java) | _O(n)_ | _O(1)_ | Easy | |
@@ -159,6 +160,7 @@ Feel free to submit pull requests, add issues and be a contributer.
159160
## Recursion
160161
| Website | Title | Solution | Time | Space | Difficulty | Note|
161162
|---------------- |---------------- | ----------- | --------------- | --------------- | ------------- |-----|
163+
| Leetcode | [22. Generate Parentheses](https://leetcode.com/problems/generate-parentheses/description/) | [Java](./java/generateParenthesis.java) | _O(4^n)_ | _O(n)_ | Medium | |
162164
| Leetcode | [50. Pow(x, n)](https://leetcode.com/problems/powx-n/description/) | [Java](./java/myPow.java) | _O()_ | _O(n)_ | Medium | |
163165
| Leetcode | [109. Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/description/) | [Java](./java/sortedListToBST.java) | _O(n)_ | _O(logn)_ | Medium | |
164166
| Leetcode | [339. Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum/description/) | [Java](./java/depthSum.java) | _O( )_ | _O( )_ | Easy | |

java/generateParenthesis.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
ass Solution {
2+
public List<String> generateParenthesis(int n) {
3+
4+
List<String> result = new ArrayList<>();
5+
if(n == 0) return result;
6+
helper("", result, n, n);
7+
return result;
8+
}
9+
10+
public void helper(String sublist, List<String> list, int left, int right)
11+
{
12+
if(left > right)
13+
return;
14+
15+
if(left > 0)
16+
helper(sublist+"(", list, left-1, right);
17+
if(right > 0)
18+
helper(sublist+")", list, left, right-1);
19+
if(left == 0 && right == 0)
20+
list.add(sublist);
21+
return;
22+
}
23+
}

java/minimumTotal.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int minimumTotal(List<List<Integer>> triangle) {
3+
int size = triangle.size();
4+
int [] result = new int[size+1];
5+
6+
for(int i=size-1; i>=0; i--)
7+
{
8+
List<Integer> temp = triangle.get(i);
9+
10+
for(int j=0; j<temp.size(); j++)
11+
result[j] = Math.min(result[j], result[j+1]) + temp.get(j);
12+
}
13+
return result[0];
14+
}
15+
}

0 commit comments

Comments
 (0)