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

Commitbe9f83e

Browse files
authored
Added tasks 11-25
1 parentc35f8f3 commitbe9f83e

File tree

33 files changed

+1034
-5
lines changed

33 files changed

+1034
-5
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespaceLeetCodeNet.Com_github_leetcode{
2+
usingSystem.Collections.Generic;
3+
4+
publicstaticclassArrayUtils{
5+
publicstaticList<List<int>>GetLists(int[][]expected){
6+
List<List<int>>expectedList=newList<List<int>>();
7+
foreach(int[]valueinexpected){
8+
List<int>expectedItem=newList<int>();
9+
expectedList.Add(expectedItem);
10+
foreach(intiteminvalue){
11+
expectedItem.Add(item);
12+
}
13+
}
14+
returnexpectedList;
15+
}
16+
}
17+
}

‎LeetCodeNet.Tests/Com_github_leetcode/LinkedListUtils.cs

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

33
publicclassLinkedListUtils{
4-
publicstaticListNodeContructLinkedList(int[]nums){
4+
publicstaticListNodeConstructLinkedList(int[]nums){
55
if(nums==null||nums.Length==0){
66
thrownewArgumentException(
77
"Please pass in a valid listValues to create a linked list.");

‎LeetCodeNet.Tests/G0001_0100/S0002_add_two_numbers/SolutionTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ namespace LeetCodeNet.G0001_0100.S0002_add_two_numbers {
66
publicclassSolutionTest{
77
[Fact]
88
publicvoidAddTwoNumbers(){
9-
ListNodelistNode1=LinkedListUtils.ContructLinkedList(newint[]{2,4,3});
10-
ListNodelistNode2=LinkedListUtils.ContructLinkedList(newint[]{5,6,4});
9+
ListNodelistNode1=LinkedListUtils.ConstructLinkedList(newint[]{2,4,3});
10+
ListNodelistNode2=LinkedListUtils.ConstructLinkedList(newint[]{5,6,4});
1111
Assert.Equal("7, 0, 8",newSolution().AddTwoNumbers(listNode1,listNode2).ToString());
1212
}
1313

@@ -18,8 +18,8 @@ public void AddTwoNumbers2() {
1818

1919
[Fact]
2020
publicvoidAddTwoNumbers3(){
21-
ListNodelistNode1=LinkedListUtils.ContructLinkedList(newint[]{9,9,9,9,9,9,9});
22-
ListNodelistNode2=LinkedListUtils.ContructLinkedList(newint[]{9,9,9,9});
21+
ListNodelistNode1=LinkedListUtils.ConstructLinkedList(newint[]{9,9,9,9,9,9,9});
22+
ListNodelistNode2=LinkedListUtils.ConstructLinkedList(newint[]{9,9,9,9});
2323
Assert.Equal("8, 9, 9, 9, 0, 0, 0, 1",newSolution().AddTwoNumbers(listNode1,listNode2).ToString());
2424
}
2525
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespaceLeetCodeNet.G0001_0100.S0011_container_with_most_water{
2+
3+
usingXunit;
4+
5+
publicclassSolutionTest{
6+
[Fact]
7+
publicvoidMaxArea(){
8+
Assert.Equal(49,newSolution().MaxArea(newint[]{1,8,6,2,5,4,8,3,7}));
9+
}
10+
11+
[Fact]
12+
publicvoidMaxArea2(){
13+
Assert.Equal(1,newSolution().MaxArea(newint[]{1,1}));
14+
}
15+
}
16+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespaceLeetCodeNet.G0001_0100.S0015_3sum{
2+
3+
usingXunit;
4+
usingLeetCodeNet.Com_github_leetcode;
5+
6+
publicclassSolutionTest{
7+
[Fact]
8+
publicvoidThreeSum(){
9+
Assert.Equal(
10+
ArrayUtils.GetLists(newint[][]{newint[]{-1,-1,2},newint[]{-1,0,1}}),
11+
newSolution().ThreeSum(newint[]{-1,0,1,2,-1,-4})
12+
);
13+
}
14+
15+
[Fact]
16+
publicvoidThreeSum2(){
17+
Assert.Equal(
18+
ArrayUtils.GetLists(newint[][]{}),
19+
newSolution().ThreeSum(newint[]{})
20+
);
21+
}
22+
23+
[Fact]
24+
publicvoidThreeSum3(){
25+
Assert.Equal(
26+
ArrayUtils.GetLists(newint[][]{}),
27+
newSolution().ThreeSum(newint[]{0})
28+
);
29+
}
30+
}
31+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
namespaceLeetCodeNet.G0001_0100.S0017_letter_combinations_of_a_phone_number{
2+
3+
usingXunit;
4+
usingSystem.Collections.Generic;
5+
6+
publicclassSolutionTest{
7+
[Fact]
8+
publicvoidLetterCombinations(){
9+
Assert.Equal(
10+
newList<string>{"ad","ae","af","bd","be","bf","cd","ce","cf"},
11+
newSolution().LetterCombinations("23")
12+
);
13+
}
14+
15+
[Fact]
16+
publicvoidLetterCombinations2(){
17+
Assert.Empty(newSolution().LetterCombinations(""));
18+
}
19+
20+
[Fact]
21+
publicvoidLetterCombinations3(){
22+
Assert.Equal(newList<string>{"a","b","c"},newSolution().LetterCombinations("2"));
23+
}
24+
25+
[Fact]
26+
publicvoidLetterCombinations4(){
27+
Assert.Equal(newList<string>{"g","h","i"},newSolution().LetterCombinations("4"));
28+
}
29+
30+
[Fact]
31+
publicvoidLetterCombinations5(){
32+
Assert.Equal(newList<string>{"j","k","l"},newSolution().LetterCombinations("5"));
33+
}
34+
35+
[Fact]
36+
publicvoidLetterCombinations6(){
37+
Assert.Equal(newList<string>{"m","n","o"},newSolution().LetterCombinations("6"));
38+
}
39+
40+
[Fact]
41+
publicvoidLetterCombinations7(){
42+
Assert.Equal(newList<string>{"p","q","r","s"},newSolution().LetterCombinations("7"));
43+
}
44+
45+
[Fact]
46+
publicvoidLetterCombinations8(){
47+
Assert.Equal(newList<string>{"t","u","v"},newSolution().LetterCombinations("8"));
48+
}
49+
50+
[Fact]
51+
publicvoidLetterCombinations9(){
52+
Assert.Equal(newList<string>{"w","x","y","z"},newSolution().LetterCombinations("9"));
53+
}
54+
}
55+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespaceLeetCodeNet.G0001_0100.S0019_remove_nth_node_from_end_of_list{
2+
3+
usingXunit;
4+
usingLeetCodeNet.Com_github_leetcode;
5+
6+
publicclassSolutionTest{
7+
[Fact]
8+
publicvoidRemoveNthFromEnd(){
9+
ListNodenode1=LinkedListUtils.ConstructLinkedList(newint[]{1,2,3,4,5});
10+
Assert.Equal("1, 2, 3, 5",newSolution().RemoveNthFromEnd(node1,2).ToString());
11+
}
12+
13+
[Fact]
14+
publicvoidRemoveNthFromEnd2(){
15+
ListNodenode1=newListNode(1);
16+
Assert.Null(newSolution().RemoveNthFromEnd(node1,1));
17+
}
18+
}
19+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespaceLeetCodeNet.G0001_0100.S0020_valid_parentheses{
2+
3+
usingXunit;
4+
5+
publicclassSolutionTest{
6+
[Fact]
7+
publicvoidIsValid(){
8+
Assert.True(newSolution().IsValid("()"));
9+
}
10+
11+
[Fact]
12+
publicvoidIsValid2(){
13+
Assert.True(newSolution().IsValid("()[]{}"));
14+
}
15+
16+
[Fact]
17+
publicvoidIsValid3(){
18+
Assert.False(newSolution().IsValid("(]"));
19+
}
20+
21+
[Fact]
22+
publicvoidIsValid4(){
23+
Assert.False(newSolution().IsValid("([)]"));
24+
}
25+
26+
[Fact]
27+
publicvoidIsValid5(){
28+
Assert.True(newSolution().IsValid("{[]}"));
29+
}
30+
}
31+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespaceLeetCodeNet.G0001_0100.S0021_merge_two_sorted_lists{
2+
3+
usingXunit;
4+
usingLeetCodeNet.Com_github_leetcode;
5+
6+
publicclassSolutionTest{
7+
[Fact]
8+
publicvoidMergeTwoLists(){
9+
ListNodel1=LinkedListUtils.CreateSinglyLinkedList(newList<int>{1,2,4});
10+
ListNodel2=LinkedListUtils.CreateSinglyLinkedList(newList<int>{1,3,4});
11+
Assert.Equal("1, 1, 2, 3, 4, 4",newSolution().MergeTwoLists(l1,l2).ToString());
12+
}
13+
14+
[Fact]
15+
publicvoidMergeTwoLists2(){
16+
Assert.Equal("0, 0",newSolution().MergeTwoLists(newListNode(),newListNode()).ToString());
17+
}
18+
}
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespaceLeetCodeNet.G0001_0100.S0022_generate_parentheses{
2+
3+
usingXunit;
4+
usingSystem.Collections.Generic;
5+
6+
publicclassSolutionTest{
7+
[Fact]
8+
publicvoidGenerateParenthesis(){
9+
Assert.Equal(
10+
newList<string>{"((()))","(()())","(())()","()(())","()()()"},
11+
newSolution().GenerateParenthesis(3)
12+
);
13+
}
14+
15+
[Fact]
16+
publicvoidGenerateParenthesis2(){
17+
Assert.Equal(
18+
newList<string>{"()"},
19+
newSolution().GenerateParenthesis(1)
20+
);
21+
}
22+
}
23+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespaceLeetCodeNet.G0001_0100.S0023_merge_k_sorted_lists{
2+
3+
usingXunit;
4+
usingSystem.Collections.Generic;
5+
usingLeetCodeNet.Com_github_leetcode;
6+
7+
publicclassSolutionTest{
8+
[Fact]
9+
publicvoidMergeKLists(){
10+
ListNodehead1=LinkedListUtils.CreateSinglyLinkedList(newList<int>{1,4,5});
11+
ListNodehead2=LinkedListUtils.CreateSinglyLinkedList(newList<int>{1,3,4});
12+
ListNodehead3=LinkedListUtils.CreateSinglyLinkedList(newList<int>{2,6});
13+
Assert.Equal(
14+
"1, 1, 2, 3, 4, 4, 5, 6",
15+
newSolution().MergeKLists(newListNode[]{head1,head2,head3}).ToString()
16+
);
17+
}
18+
19+
[Fact]
20+
publicvoidMergeKLists2(){
21+
ListNodehead1=LinkedListUtils.CreateSinglyLinkedList(newList<int>{1,3,5,7,11});
22+
ListNodehead2=LinkedListUtils.CreateSinglyLinkedList(newList<int>{2,8,12});
23+
ListNodehead3=LinkedListUtils.CreateSinglyLinkedList(newList<int>{4,6,9,10});
24+
Assert.Equal(
25+
"1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12",
26+
newSolution().MergeKLists(newListNode[]{head1,head2,head3}).ToString()
27+
);
28+
}
29+
}
30+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespaceLeetCodeNet.G0001_0100.S0024_swap_nodes_in_pairs{
2+
3+
usingXunit;
4+
usingSystem.Collections.Generic;
5+
usingLeetCodeNet.Com_github_leetcode;
6+
7+
publicclassSolutionTest{
8+
[Fact]
9+
publicvoidSwapPairs(){
10+
ListNodehead=LinkedListUtils.CreateSinglyLinkedList(newList<int>{1,2,3,4});
11+
Assert.Equal("2, 1, 4, 3",newSolution().SwapPairs(head).ToString());
12+
}
13+
14+
[Fact]
15+
publicvoidSwapPairs2(){
16+
Assert.Equal("1",newSolution().SwapPairs(newListNode(1)).ToString());
17+
}
18+
}
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespaceLeetCodeNet.G0001_0100.S0025_reverse_nodes_in_k_group{
2+
3+
usingXunit;
4+
usingSystem.Collections.Generic;
5+
usingLeetCodeNet.Com_github_leetcode;
6+
7+
publicclassSolutionTest{
8+
[Fact]
9+
publicvoidReverseKGroup(){
10+
ListNodehead=LinkedListUtils.ConstructLinkedList(newint[]{1,2,3,4,5});
11+
Assert.Equal("2, 1, 4, 3, 5",newSolution().ReverseKGroup(head,2).ToString());
12+
}
13+
14+
[Fact]
15+
publicvoidReverseKGroup2(){
16+
ListNodehead=LinkedListUtils.ConstructLinkedList(newint[]{1,2,3,4,5});
17+
Assert.Equal("3, 2, 1, 4, 5",newSolution().ReverseKGroup(head,3).ToString());
18+
}
19+
}
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespaceLeetCodeNet.G0001_0100.S0011_container_with_most_water{
2+
3+
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Greedy #Two_Pointers
4+
// #Algorithm_II_Day_4_Two_Pointers #Big_O_Time_O(n)_Space_O(1)
5+
// #2023_12_26_Time_248_ms_(11.15%)_Space_62.1_MB_(5.59%)
6+
7+
publicclassSolution{
8+
publicintMaxArea(int[]height){
9+
intmaxArea=-1;
10+
intleft=0;
11+
intright=height.Length-1;
12+
13+
while(left<right){
14+
if(height[left]<height[right]){
15+
maxArea=Math.Max(maxArea,height[left]*(right-left));
16+
left++;
17+
}else{
18+
maxArea=Math.Max(maxArea,height[right]*(right-left));
19+
right--;
20+
}
21+
}
22+
23+
returnmaxArea;
24+
}
25+
}
26+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
11\. Container With Most Water
2+
3+
Medium
4+
5+
Given`n` non-negative integers <code>a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>n</sub></code> , where each represents a point at coordinate <code>(i, a<sub>i</sub>)</code>.`n` vertical lines are drawn such that the two endpoints of the line`i` is at <code>(i, a<sub>i</sub>)</code> and`(i, 0)`. Find two lines, which, together with the x-axis forms a container, such that the container contains the most water.
6+
7+
**Notice** that you may not slant the container.
8+
9+
**Example 1:**
10+
11+
![](https://s3-lc-upload.s3.amazonaws.com/uploads/2018/07/17/question_11.jpg)
12+
13+
**Input:** height =[1,8,6,2,5,4,8,3,7]
14+
15+
**Output:** 49
16+
17+
**Explanation:** The above vertical lines are represented by array[1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
18+
19+
**Example 2:**
20+
21+
**Input:** height =[1,1]
22+
23+
**Output:** 1
24+
25+
**Example 3:**
26+
27+
**Input:** height =[4,3,2,1,4]
28+
29+
**Output:** 16
30+
31+
**Example 4:**
32+
33+
**Input:** height =[1,2,1]
34+
35+
**Output:** 2
36+
37+
**Constraints:**
38+
39+
*`n == height.length`
40+
* <code>2 <= n <= 10<sup>5</sup></code>
41+
* <code>0 <= height[i] <= 10<sup>4</sup></code>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp