Skip to content

Commit 3a3604b

Browse files
author
Li Li
committed
rearrange folders
1 parent 345b7a4 commit 3a3604b

27 files changed

+12
-16
lines changed

LeetcodeCShaprDotNetCore/Solution.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,16 @@
55

66
namespace LeetcodeCShaprDotNetCore {
77
public class Solution {
8-
public IList<IList<int>> Generate(int numRows) {
9-
IList<IList<int>> result = new List<IList<int>>();
10-
for (int row = 0; row < numRows; row++) {
11-
IList<int> list = new List<int>();
12-
for (int i = 0; i < row + 1; i++) {
13-
if (i == 0 || i == row) {
14-
list.Add(1);
15-
} else {
16-
var preList = result[row - 1];
17-
list.Add(preList[i - 1] + preList[i]);
18-
}
19-
}
20-
result.Add(list);
21-
}
22-
return result;
8+
public TreeNode SortedArrayToBST(int[] nums) {
9+
return SortedArrayToBST(nums, 0, nums.Length - 1);
10+
}
11+
private TreeNode SortedArrayToBST(int[] nums, int left, int right) {
12+
if (nums == null || nums.Length == 0 || left > right) return null;
13+
int mid = left + (right - left) / 2;
14+
TreeNode root = new TreeNode(nums[mid]);
15+
root.left = SortedArrayToBST(nums, left, mid - 1);
16+
root.right = SortedArrayToBST(nums, mid + 1, right);
17+
return root;
2318
}
2419
}
2520
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
I will use this repository to make notes for leetcode solutions and classify the problems by different topics.
44

55
## Solved Problem List
6-
Total solved: 71
6+
Total solved: 72
77

88
### top-interview-questions
99

@@ -12,6 +12,7 @@ ID | Difficulty | Tags | Solution
1212
14 | Easy | String | [Longest Common Prefix](https://github.com/kflili/LeetcodeCShaprDotNetCore/blob/master/Algorithms%20Basics/top-interview-questions/14.%20Longest%20Common%20Prefix.cs)
1313
38 | Easy | String | [Count and Say](https://github.com/kflili/LeetcodeCShaprDotNetCore/blob/master/Algorithms%20Basics/top-interview-questions/38.%20Count%20and%20Say.cs)
1414
53 | Easy | Dynamic Programming, Divide and Conquer | [Maximum Subarray](https://github.com/kflili/LeetcodeCShaprDotNetCore/blob/master/Algorithms%20Basics/top-interview-questions/53.%20Maximum%20Subarray.cs)
15+
108 | Easy | Tree, DFS | [Convert Sorted Array to Binary Search Tree](https://github.com/kflili/LeetcodeCShaprDotNetCore/blob/master/Algorithms%20Basics/top-interview-questions/108.%20Convert%20Sorted%20Array%20to%20Binary%20Search%20Tree.cs)
1516
118 | Easy | Array, Math | [Pascal's Triangle](https://github.com/kflili/LeetcodeCShaprDotNetCore/blob/master/Algorithms%20Basics/top-interview-questions/118.%20Pascal's%20Triangle.cs)
1617
121 | Easy | Array, Dynamic Programming | [Best Time to Buy and Sell Stock](https://github.com/kflili/LeetcodeCShaprDotNetCore/blob/master/Algorithms%20Basics/top-interview-questions/121.%20Best%20Time%20to%20Buy%20and%20Sell%20Stock.cs)
1718
122 | Easy | Array | [Best Time to Buy and Sell Stock II](https://github.com/kflili/LeetcodeCShaprDotNetCore/blob/master/Algorithms%20Basics/top-interview-questions/122.%20Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II.cs)

0 commit comments

Comments
 (0)