Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfe6a6fd

Browse files
authored
Added tasks 206-238
1 parent603db53 commitfe6a6fd

File tree

36 files changed

+1001
-6
lines changed

36 files changed

+1001
-6
lines changed

‎LeetCodeNet.Tests/G0101_0200/S0102_binary_tree_level_order_traversal/SolutionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespaceLeetCodeNet.G0101_0200.S0102_binary_tree_level_order_traversal{
22

33
usingXunit;
4-
usingCom_github_leetcode;
4+
usingLeetCodeNet.Com_github_leetcode;
55

66
publicclassSolutionTest{
77
[Fact]

‎LeetCodeNet.Tests/G0101_0200/S0104_maximum_depth_of_binary_tree/SolutionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespaceLeetCodeNet.G0101_0200.S0104_maximum_depth_of_binary_tree{
22

33
usingXunit;
4-
usingCom_github_leetcode;
4+
usingLeetCodeNet.Com_github_leetcode;
55

66
publicclassSolutionTest{
77
[Fact]

‎LeetCodeNet.Tests/G0101_0200/S0124_binary_tree_maximum_path_sum/SolutionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespaceLeetCodeNet.G0101_0200.S0124_binary_tree_maximum_path_sum{
22

33
usingXunit;
4-
usingCom_github_leetcode;
4+
usingLeetCodeNet.Com_github_leetcode;
55

66
publicclassSolutionTest{
77
[Fact]

‎LeetCodeNet.Tests/G0101_0200/S0142_linked_list_cycle_ii/SolutionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void DetectCycle2() {
2525
[Fact]
2626
publicvoidDetectCycle3(){
2727
ListNodelistNode1=newListNode(1);
28-
Assert.Equal(null,newSolution().DetectCycle(listNode1));
28+
Assert.Null(newSolution().DetectCycle(listNode1));
2929
}
3030
}
3131
}

‎LeetCodeNet.Tests/G0101_0200/S0148_sort_list/SolutionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void SortList2() {
2525

2626
[Fact]
2727
publicvoidSortList3(){
28-
Assert.Equal(null,newSolution().SortList(null));
28+
Assert.Null(newSolution().SortList(null));
2929
}
3030
}
3131
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespaceLeetCodeNet.G0201_0300.S0206_reverse_linked_list{
2+
3+
usingXunit;
4+
usingLeetCodeNet.Com_github_leetcode;
5+
6+
publicclassSolutionTest{
7+
[Fact]
8+
publicvoidReverseList(){
9+
ListNodeheadActual=newListNode(1);
10+
headActual.next=newListNode(2);
11+
headActual.next.next=newListNode(3);
12+
headActual.next.next.next=newListNode(4);
13+
headActual.next.next.next.next=newListNode(5);
14+
Assert.Equal("5, 4, 3, 2, 1",newSolution().ReverseList(headActual).ToString());
15+
}
16+
17+
[Fact]
18+
publicvoidReverseList2(){
19+
ListNodeheadActual=newListNode(1);
20+
headActual.next=newListNode(2);
21+
Assert.Equal("2, 1",newSolution().ReverseList(headActual).ToString());
22+
}
23+
24+
[Fact]
25+
publicvoidReverseList3(){
26+
Assert.Null(newSolution().ReverseList(null));
27+
}
28+
}
29+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespaceLeetCodeNet.G0201_0300.S0207_course_schedule{
2+
3+
usingXunit;
4+
5+
publicclassSolutionTest{
6+
[Fact]
7+
publicvoidCanFinish(){
8+
Assert.True(newSolution().CanFinish(2,newint[][]{newint[]{1,0}}));
9+
}
10+
11+
[Fact]
12+
publicvoidCanFinish2(){
13+
Assert.False(newSolution().CanFinish(2,newint[][]{newint[]{1,0},newint[]{0,1}}));
14+
}
15+
}
16+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespaceLeetCodeNet.G0201_0300.S0208_implement_trie_prefix_tree{
2+
3+
usingXunit;
4+
5+
publicclassTrieTest{
6+
[Fact]
7+
publicvoidTrie(){
8+
Trietrie=newTrie();
9+
trie.Insert("apple");
10+
// return True
11+
Assert.True(trie.Search("apple"));
12+
// return False
13+
Assert.False(trie.Search("app"));
14+
// return True
15+
Assert.True(trie.StartsWith("app"));
16+
trie.Insert("app");
17+
// return True
18+
Assert.True(trie.Search("app"));
19+
}
20+
}
21+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespaceLeetCodeNet.G0201_0300.S0215_kth_largest_element_in_an_array{
2+
3+
usingXunit;
4+
5+
publicclassSolutionTest{
6+
[Fact]
7+
publicvoidFindKthLargest(){
8+
Assert.Equal(5,newSolution().FindKthLargest(newint[]{3,2,1,5,6,4},2));
9+
}
10+
11+
[Fact]
12+
publicvoidFindKthLargest2(){
13+
Assert.Equal(4,newSolution().FindKthLargest(newint[]{3,2,3,1,2,4,5,5,6},4));
14+
}
15+
}
16+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespaceLeetCodeNet.G0201_0300.S0221_maximal_square{
2+
3+
usingXunit;
4+
5+
publicclassSolutionTest{
6+
[Fact]
7+
publicvoidMaximalSquare(){
8+
char[][]input={
9+
new[]{'1','0','1','0','0'},
10+
new[]{'1','0','1','1','1'},
11+
new[]{'1','1','1','1','1'},
12+
new[]{'1','0','0','1','0'}
13+
};
14+
Assert.Equal(4,newSolution().MaximalSquare(input));
15+
}
16+
17+
[Fact]
18+
publicvoidMaximalSquare2(){
19+
char[][]input={new[]{'0','1'},new[]{'1','0'}};
20+
Assert.Equal(1,newSolution().MaximalSquare(input));
21+
}
22+
23+
[Fact]
24+
publicvoidMaximalSquare3(){
25+
char[][]input={new[]{'0'}};
26+
Assert.Equal(0,newSolution().MaximalSquare(input));
27+
}
28+
}
29+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespaceLeetCodeNet.G0201_0300.S0226_invert_binary_tree{
2+
3+
usingXunit;
4+
usingLeetCodeNet.Com_github_leetcode;
5+
6+
publicclassSolutionTest{
7+
[Fact]
8+
publicvoidInvertTree(){
9+
TreeNoderoot=TreeUtils.ConstructBinaryTree(newList<int?>{4,2,7,1,3,6,9});
10+
Assert.Equal("4,7,9,6,2,3,1",newSolution().InvertTree(root).ToString());
11+
}
12+
13+
[Fact]
14+
publicvoidInvertTree2(){
15+
TreeNoderoot=TreeUtils.ConstructBinaryTree(newList<int?>{2,1,3});
16+
Assert.Equal("2,3,1",newSolution().InvertTree(root).ToString());
17+
}
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespaceLeetCodeNet.G0201_0300.S0230_kth_smallest_element_in_a_bst{
2+
3+
usingXunit;
4+
usingLeetCodeNet.Com_github_leetcode;
5+
6+
publicclassSolutionTest{
7+
[Fact]
8+
publicvoidKthSmallest(){
9+
TreeNoderoot=TreeNode.Create(newList<int?>{3,1,4,null,2});
10+
Assert.Equal(1,newSolution().KthSmallest(root,1));
11+
}
12+
13+
[Fact]
14+
publicvoidKthSmallest2(){
15+
TreeNoderoot=TreeNode.Create(newList<int?>{5,3,6,2,4,null,null,1});
16+
Assert.Equal(3,newSolution().KthSmallest(root,3));
17+
}
18+
}
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespaceLeetCodeNet.G0201_0300.S0234_palindrome_linked_list{
2+
3+
usingXunit;
4+
usingLeetCodeNet.Com_github_leetcode;
5+
6+
publicclassSolutionTest{
7+
[Fact]
8+
publicvoidIsPalindrome(){
9+
ListNodeheadActual=newListNode(1);
10+
headActual.next=newListNode(2);
11+
headActual.next.next=newListNode(2);
12+
headActual.next.next.next=newListNode(1);
13+
Assert.True(newSolution().IsPalindrome(headActual));
14+
}
15+
16+
[Fact]
17+
publicvoidIsPalindrome2(){
18+
ListNodeheadActual=newListNode(1);
19+
headActual.next=newListNode(2);
20+
Assert.False(newSolution().IsPalindrome(headActual));
21+
}
22+
}
23+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespaceLeetCodeNet.G0201_0300.S0236_lowest_common_ancestor_of_a_binary_tree{
2+
3+
usingXunit;
4+
usingLeetCodeNet.Com_github_leetcode;
5+
6+
publicclassSolutionTest{
7+
[Fact]
8+
publicvoidLowestCommonAncestor(){
9+
TreeNodeleftNodeLeftNode=newTreeNode(6);
10+
TreeNodeleftNodeRightNode=newTreeNode(2,newTreeNode(7),newTreeNode(4));
11+
TreeNodeleftNode=newTreeNode(5,leftNodeLeftNode,leftNodeRightNode);
12+
TreeNoderightNode=newTreeNode(1,newTreeNode(0),newTreeNode(8));
13+
TreeNoderoot=newTreeNode(3,leftNode,rightNode);
14+
Assert.Equal(3,newSolution().LowestCommonAncestor(root,newTreeNode(5),newTreeNode(1)).val);
15+
}
16+
17+
[Fact]
18+
publicvoidLowestCommonAncestor2(){
19+
TreeNodeleftNodeLeftNode=newTreeNode(6);
20+
TreeNodeleftNodeRightNode=newTreeNode(2,newTreeNode(7),newTreeNode(4));
21+
TreeNodeleftNode=newTreeNode(5,leftNodeLeftNode,leftNodeRightNode);
22+
TreeNoderightNode=newTreeNode(1,newTreeNode(0),newTreeNode(8));
23+
TreeNoderoot=newTreeNode(3,leftNode,rightNode);
24+
Assert.Equal(5,newSolution().LowestCommonAncestor(root,newTreeNode(5),newTreeNode(4)).val);
25+
}
26+
27+
[Fact]
28+
publicvoidLowestCommonAncestor3(){
29+
Assert.Equal(2,
30+
newSolution().LowestCommonAncestor(
31+
newTreeNode(2,newTreeNode(1),null),
32+
newTreeNode(2),
33+
newTreeNode(1)).val);
34+
}
35+
}
36+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespaceLeetCodeNet.G0201_0300.S0238_product_of_array_except_self{
2+
3+
usingXunit;
4+
5+
publicclassSolutionTest{
6+
[Fact]
7+
publicvoidProductExceptSelf(){
8+
Assert.Equal(
9+
newint[]{24,12,8,6},
10+
newSolution().ProductExceptSelf(newint[]{1,2,3,4})
11+
);
12+
}
13+
14+
[Fact]
15+
publicvoidProductExceptSelf2(){
16+
Assert.Equal(
17+
newint[]{0,0,9,0,0},
18+
newSolution().ProductExceptSelf(newint[]{-1,1,0,-3,3})
19+
);
20+
}
21+
}
22+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespaceLeetCodeNet.G0201_0300.S0206_reverse_linked_list{
2+
3+
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Linked_List #Recursion
4+
// #Data_Structure_I_Day_8_Linked_List #Algorithm_I_Day_10_Recursion_Backtracking
5+
// #Level_1_Day_3_Linked_List #Udemy_Linked_List #Big_O_Time_O(N)_Space_O(1)
6+
// #2024_01_10_Time_57_ms_(95.02%)_Space_40.9_MB_(19.99%)
7+
8+
usingLeetCodeNet.Com_github_leetcode;
9+
10+
/**
11+
* Definition for singly-linked list.
12+
* public class ListNode {
13+
* public int val;
14+
* public ListNode next;
15+
* public ListNode(int val=0, ListNode next=null) {
16+
* this.val = val;
17+
* this.next = next;
18+
* }
19+
* }
20+
*/
21+
publicclassSolution{
22+
publicListNodeReverseList(ListNodehead){
23+
ListNodeprev=null;
24+
ListNodecurr=head;
25+
while(curr!=null){
26+
ListNodenext=curr.next;
27+
curr.next=prev;
28+
prev=curr;
29+
curr=next;
30+
}
31+
returnprev;
32+
}
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
206\. Reverse Linked List
2+
3+
Easy
4+
5+
Given the`head` of a singly linked list, reverse the list, and return_the reversed list_.
6+
7+
**Example 1:**
8+
9+
![](https://assets.leetcode.com/uploads/2021/02/19/rev1ex1.jpg)
10+
11+
**Input:** head =[1,2,3,4,5]
12+
13+
**Output:**[5,4,3,2,1]
14+
15+
**Example 2:**
16+
17+
![](https://assets.leetcode.com/uploads/2021/02/19/rev1ex2.jpg)
18+
19+
**Input:** head =[1,2]
20+
21+
**Output:**[2,1]
22+
23+
**Example 3:**
24+
25+
**Input:** head =[]
26+
27+
**Output:**[]
28+
29+
**Constraints:**
30+
31+
* The number of nodes in the list is the range`[0, 5000]`.
32+
*`-5000 <= Node.val <= 5000`
33+
34+
**Follow up:** A linked list can be reversed either iteratively or recursively. Could you implement both?

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp