Skip to content

Commit 662c0b2

Browse files
authored
Improved tasks 103-117
1 parent 5211e6f commit 662c0b2

File tree

11 files changed

+122
-106
lines changed

11 files changed

+122
-106
lines changed
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
namespace LeetCodeNet.G0101_0200.S0106_construct_binary_tree_from_inorder_and_postorder_traversal {
22

3-
using Xunit;
4-
using LeetCodeNet.Com_github_leetcode;
5-
6-
public class SolutionTest {
7-
[Fact]
8-
public void ConstructBinaryTree() {
9-
int[] inorder = {9, 3, 15, 20, 7};
10-
int[] postorder = {9, 15, 7, 20, 3};
11-
TreeNode actual = new Solution().BuildTree(inorder, postorder);
12-
Assert.Equal("3,9,20,15,7", actual.ToString());
13-
}
3+
using Xunit;
4+
using LeetCodeNet.Com_github_leetcode;
145

15-
[Fact]
16-
public void ConstructBinaryTree2() {
17-
int[] inorder = {-1};
18-
int[] postorder = {-1};
19-
TreeNode actual = new Solution().BuildTree(inorder, postorder);
20-
Assert.Equal("-1", actual.ToString());
21-
}
6+
public class SolutionTest {
7+
[Fact]
8+
public void ConstructBinaryTree() {
9+
int[] inorder = {9, 3, 15, 20, 7};
10+
int[] postorder = {9, 15, 7, 20, 3};
11+
TreeNode actual = new Solution().BuildTree(inorder, postorder);
12+
Assert.Equal("3,9,20,15,7", actual.ToString());
2213
}
23-
}
14+
15+
[Fact]
16+
public void ConstructBinaryTree2() {
17+
int[] inorder = {-1};
18+
int[] postorder = {-1};
19+
TreeNode actual = new Solution().BuildTree(inorder, postorder);
20+
Assert.Equal("-1", actual.ToString());
21+
}
22+
}
23+
}
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
namespace LeetCodeNet.G0101_0200.S0108_convert_sorted_array_to_binary_search_tree {
22

3-
using Xunit;
4-
using LeetCodeNet.Com_github_leetcode;
5-
6-
public class SolutionTest {
7-
[Fact]
8-
public void SortedArrayToBST() {
9-
var actual = new Solution().SortedArrayToBST(new int[] {-10, -3, 0, 5, 9});
10-
Assert.Equal("0,-10,null,-3,5,null,9", actual.ToString());
11-
}
3+
using Xunit;
4+
using LeetCodeNet.Com_github_leetcode;
125

13-
[Fact]
14-
public void SortedArrayToBST2() {
15-
var actual = new Solution().SortedArrayToBST(new int[] {1, 3});
16-
Assert.Equal("1,null,3", actual.ToString());
17-
}
6+
public class SolutionTest {
7+
[Fact]
8+
public void SortedArrayToBST() {
9+
var actual = new Solution().SortedArrayToBST(new int[] {-10, -3, 0, 5, 9});
10+
Assert.Equal("0,-10,null,-3,5,null,9", actual.ToString());
1811
}
19-
}
12+
13+
[Fact]
14+
public void SortedArrayToBST2() {
15+
var actual = new Solution().SortedArrayToBST(new int[] {1, 3});
16+
Assert.Equal("1,null,3", actual.ToString());
17+
}
18+
}
19+
}
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
namespace LeetCodeNet.G0101_0200.S0112_path_sum {
22

3-
using Xunit;
4-
using System.Collections.Generic;
5-
using LeetCodeNet.Com_github_leetcode;
3+
using Xunit;
4+
using System.Collections.Generic;
5+
using LeetCodeNet.Com_github_leetcode;
66

7-
public class SolutionTest {
8-
[Fact]
9-
public void HasPathSum() {
10-
var root = TreeNode.Create(new List<int?> {5, 4, 8, 11, null, 13, 4, 7, 2, null, null, null, 1});
11-
Assert.True(new Solution().HasPathSum(root, 22));
12-
}
7+
public class SolutionTest {
8+
[Fact]
9+
public void HasPathSum() {
10+
var root = TreeNode.Create(new List<int?> {5, 4, 8, 11, null, 13, 4, 7, 2, null, null, null, 1});
11+
Assert.True(new Solution().HasPathSum(root, 22));
12+
}
1313

14-
[Fact]
15-
public void HasPathSum2() {
16-
var root = TreeNode.Create(new List<int?> {1, 2, 3});
17-
Assert.False(new Solution().HasPathSum(root, 22));
18-
}
14+
[Fact]
15+
public void HasPathSum2() {
16+
var root = TreeNode.Create(new List<int?> {1, 2, 3});
17+
Assert.False(new Solution().HasPathSum(root, 22));
18+
}
1919

20-
[Fact]
21-
public void HasPathSum3() {
22-
Assert.False(new Solution().HasPathSum(null, 0));
23-
}
20+
[Fact]
21+
public void HasPathSum3() {
22+
Assert.False(new Solution().HasPathSum(null, 0));
2423
}
25-
}
24+
}
25+
}
Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
namespace LeetCodeNet.G0101_0200.S0117_populating_next_right_pointers_in_each_node_ii {
22

3-
using Xunit;
4-
5-
public class SolutionTest {
6-
[Fact]
7-
public void Connect() {
8-
Assert.Null(new Solution().Connect(null));
9-
}
10-
11-
[Fact]
12-
public void Connect2() {
13-
var node = new Node(
14-
1,
15-
new Node(2, new Node(4), new Node(5), null),
16-
new Node(3, null, new Node(7), null),
17-
null);
18-
19-
var node7 = new Node(7);
20-
var node3 = new Node(3, null, node7, null);
21-
var node5 = new Node(5, null, null, node7);
22-
var node4 = new Node(4, null, null, node5);
23-
var node2 = new Node(2, node4, node5, node3);
24-
var node1 = new Node(1, node2, node3, null);
25-
26-
Assert.Equal(node1.ToString(), new Solution().Connect(node).ToString());
27-
}
28-
29-
[Fact]
30-
public void Connect3() {
31-
var node = new Node(
32-
1,
33-
new Node(2, new Node(4, new Node(7), null, null), new Node(5), null),
34-
new Node(3, null, new Node(6, null, new Node(8), null), null),
35-
null);
36-
37-
var node8 = new Node(8, null, null, null);
38-
var node7 = new Node(7, null, null, node8);
39-
var node6 = new Node(6, null, node8, null);
40-
var node3 = new Node(3, null, node6, null);
41-
var node5 = new Node(5, null, null, node6);
42-
var node4 = new Node(4, node7, null, node5);
43-
var node2 = new Node(2, node4, node5, node3);
44-
var node1 = new Node(1, node2, node3, null);
45-
46-
Assert.Equal(node1.ToString(), new Solution().Connect(node).ToString());
47-
}
3+
using Xunit;
4+
5+
public class SolutionTest {
6+
[Fact]
7+
public void Connect() {
8+
Assert.Null(new Solution().Connect(null));
9+
}
10+
11+
[Fact]
12+
public void Connect2() {
13+
var node = new Node(
14+
1,
15+
new Node(2, new Node(4), new Node(5), null),
16+
new Node(3, null, new Node(7), null),
17+
null);
18+
19+
var node7 = new Node(7);
20+
var node3 = new Node(3, null, node7, null);
21+
var node5 = new Node(5, null, null, node7);
22+
var node4 = new Node(4, null, null, node5);
23+
var node2 = new Node(2, node4, node5, node3);
24+
var node1 = new Node(1, node2, node3, null);
25+
26+
Assert.Equal(node1.ToString(), new Solution().Connect(node).ToString());
27+
}
28+
29+
[Fact]
30+
public void Connect3() {
31+
var node = new Node(
32+
1,
33+
new Node(2, new Node(4, new Node(7), null, null), new Node(5), null),
34+
new Node(3, null, new Node(6, null, new Node(8), null), null),
35+
null);
36+
37+
var node8 = new Node(8, null, null, null);
38+
var node7 = new Node(7, null, null, node8);
39+
var node6 = new Node(6, null, node8, null);
40+
var node3 = new Node(3, null, node6, null);
41+
var node5 = new Node(5, null, null, node6);
42+
var node4 = new Node(4, node7, null, node5);
43+
var node2 = new Node(2, node4, node5, node3);
44+
var node1 = new Node(1, node2, node3, null);
45+
46+
Assert.Equal(node1.ToString(), new Solution().Connect(node).ToString());
4847
}
49-
}
48+
}
49+
}

LeetCodeNet/G0101_0200/S0103_binary_tree_zigzag_level_order_traversal/Solution.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ public IList<IList<int>> ZigzagLevelOrder(TreeNode root) {
5858
return results;
5959
}
6060
}
61-
}
61+
}

LeetCodeNet/G0101_0200/S0106_construct_binary_tree_from_inorder_and_postorder_traversal/Solution.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ private TreeNode Helper(int[] inorder, int[] postorder, ref int inIndex, ref int
3636
return root;
3737
}
3838
}
39-
}
39+
}

LeetCodeNet/G0101_0200/S0108_convert_sorted_array_to_binary_search_tree/Solution.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ private TreeNode MakeTree(int[] nums, int left, int right) {
3535
return midNode;
3636
}
3737
}
38-
}
38+
}

LeetCodeNet/G0101_0200/S0112_path_sum/Solution.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ public bool HasPathSum(TreeNode root, int sum) {
2929
return HasPathSum(root.left, (int)(sum - root.val)) || HasPathSum(root.right, (int)(sum - root.val));
3030
}
3131
}
32-
}
32+
}

LeetCodeNet/G0101_0200/S0117_populating_next_right_pointers_in_each_node_ii/Node.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ public Node(int _val, Node _left, Node _right, Node _next) {
1919
next = _next;
2020
}
2121
}
22-
}
22+
}

LeetCodeNet/G0101_0200/S0117_populating_next_right_pointers_in_each_node_ii/Solution.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public Node(int _val, Node _left, Node _right, Node _next) {
2626
}
2727
}
2828
*/
29-
3029
public class Solution {
3130
public Node Connect(Node root) {
3231
if (root == null) {
@@ -67,4 +66,4 @@ private Node AdjacentRightNode(Node root) {
6766
return null;
6867
}
6968
}
70-
}
69+
}

0 commit comments

Comments
 (0)