Skip to content

Commit f3fad08

Browse files
authored
Added tasks 239-394
1 parent c178a7b commit f3fad08

File tree

31 files changed

+937
-0
lines changed

31 files changed

+937
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace LeetCodeNet.G0201_0300.S0239_sliding_window_maximum {
2+
3+
using Xunit;
4+
5+
public class SolutionTest {
6+
[Fact]
7+
public void MaxSlidingWindow() {
8+
Assert.Equal(new int[] {3, 3, 5, 5, 6, 7},
9+
new Solution().MaxSlidingWindow(new int[] {1, 3, -1, -3, 5, 3, 6, 7}, 3));
10+
}
11+
12+
[Fact]
13+
public void MaxSlidingWindow2() {
14+
Assert.Equal(new int[] {1}, new Solution().MaxSlidingWindow(new int[] {1}, 1));
15+
}
16+
}
17+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace LeetCodeNet.G0201_0300.S0240_search_a_2d_matrix_ii {
2+
3+
using Xunit;
4+
5+
public class SolutionTest {
6+
[Fact]
7+
public void SearchMatrix() {
8+
int[][] matrix = {
9+
new int[] {1, 4, 7, 11, 15},
10+
new int[] {2, 5, 8, 12, 19},
11+
new int[] {3, 6, 9, 16, 22},
12+
new int[] {10, 13, 14, 17, 24},
13+
new int[] {18, 21, 23, 26, 30}
14+
};
15+
Assert.Equal(true, new Solution().SearchMatrix(matrix, 5));
16+
}
17+
18+
[Fact]
19+
public void SearchMatrix2() {
20+
int[][] matrix = {
21+
new int[] {1, 4, 7, 11, 15},
22+
new int[] {2, 5, 8, 12, 19},
23+
new int[] {3, 6, 9, 16, 22},
24+
new int[] {10, 13, 14, 17, 24},
25+
new int[] {18, 21, 23, 26, 30}
26+
};
27+
Assert.Equal(false, new Solution().SearchMatrix(matrix, 20));
28+
}
29+
}
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace LeetCodeNet.G0201_0300.S0283_move_zeroes {
2+
3+
using Xunit;
4+
5+
public class SolutionTest {
6+
[Fact]
7+
public void MoveZeroes() {
8+
int[] array = {0, 1, 0, 3, 12};
9+
new Solution().MoveZeroes(array);
10+
Assert.Equal(new int[] {1, 3, 12, 0, 0}, array);
11+
}
12+
13+
[Fact]
14+
public void MoveZeroes2() {
15+
int[] array = {0};
16+
new Solution().MoveZeroes(array);
17+
Assert.Equal(new int[] {0}, array);
18+
}
19+
}
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace LeetCodeNet.G0201_0300.S0287_find_the_duplicate_number {
2+
3+
using Xunit;
4+
5+
public class SolutionTest {
6+
[Fact]
7+
public void FindDuplicate() {
8+
Assert.Equal(2, new Solution().FindDuplicate(new int[] {1, 3, 4, 2, 2}));
9+
}
10+
11+
[Fact]
12+
public void FindDuplicate2() {
13+
Assert.Equal(3, new Solution().FindDuplicate(new int[] {3, 1, 3, 4, 2}));
14+
}
15+
16+
[Fact]
17+
public void FindDuplicate3() {
18+
Assert.Equal(1, new Solution().FindDuplicate(new int[] {1, 1}));
19+
}
20+
21+
[Fact]
22+
public void FindDuplicate4() {
23+
Assert.Equal(1, new Solution().FindDuplicate(new int[] {1, 1, 2}));
24+
}
25+
}
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace LeetCodeNet.G0201_0300.S0295_find_median_from_data_stream {
2+
3+
using Xunit;
4+
5+
public class MedianFinderTest {
6+
[Fact]
7+
public void MedianFinder() {
8+
MedianFinder medianFinder = new MedianFinder();
9+
// arr = [1]
10+
medianFinder.AddNum(1);
11+
// arr = [1, 2]
12+
medianFinder.AddNum(2);
13+
// return 1.5 (i.e., (1 + 2) / 2)
14+
Assert.Equal(1.5, medianFinder.FindMedian());
15+
// arr[1, 2, 3]
16+
medianFinder.AddNum(3);
17+
// return 2.0
18+
Assert.Equal(2.0, medianFinder.FindMedian());
19+
}
20+
21+
[Fact]
22+
public void MedianFinder2() {
23+
MedianFinder medianFinder = new MedianFinder();
24+
medianFinder.AddNum(1);
25+
medianFinder.AddNum(3);
26+
medianFinder.AddNum(-1);
27+
Assert.Equal(1.0, medianFinder.FindMedian());
28+
}
29+
}
30+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace LeetCodeNet.G0201_0300.S0300_longest_increasing_subsequence {
2+
3+
using Xunit;
4+
5+
public class SolutionTest {
6+
[Fact]
7+
public void LengthOfLIS() {
8+
Assert.Equal(4, new Solution().LengthOfLIS(new int[] {10, 9, 2, 5, 3, 7, 101, 18}));
9+
}
10+
11+
[Fact]
12+
public void LengthOfLIS2() {
13+
Assert.Equal(4, new Solution().LengthOfLIS(new int[] {0, 1, 0, 3, 2, 3}));
14+
}
15+
16+
[Fact]
17+
public void LengthOfLIS3() {
18+
Assert.Equal(1, new Solution().LengthOfLIS(new int[] {7, 7, 7, 7, 7, 7, 7}));
19+
}
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace LeetCodeNet.G0301_0400.S0322_coin_change {
2+
3+
using Xunit;
4+
5+
public class SolutionTest {
6+
[Fact]
7+
public void CoinChange() {
8+
Assert.Equal(3, new Solution().CoinChange(new int[] {1, 2, 5}, 11));
9+
}
10+
11+
[Fact]
12+
public void CoinChange2() {
13+
Assert.Equal(-1, new Solution().CoinChange(new int[] {2}, 3));
14+
}
15+
16+
[Fact]
17+
public void CoinChange3() {
18+
Assert.Equal(0, new Solution().CoinChange(new int[] {1}, 0));
19+
}
20+
}
21+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace LeetCodeNet.G0301_0400.S0338_counting_bits {
2+
3+
using Xunit;
4+
5+
public class SolutionTest {
6+
[Fact]
7+
public void CountBits() {
8+
Assert.Equal(new int[] {0, 1, 1}, new Solution().CountBits(2));
9+
}
10+
11+
[Fact]
12+
public void CountBits2() {
13+
Assert.Equal(new int[] {0, 1, 1, 2, 1, 2}, new Solution().CountBits(5));
14+
}
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace LeetCodeNet.G0301_0400.S0347_top_k_frequent_elements {
2+
3+
using Xunit;
4+
5+
public class SolutionTest {
6+
[Fact]
7+
public void TopKFrequent() {
8+
Assert.Equal(new int[] {1, 2},
9+
new Solution().TopKFrequent(new int[] {1, 1, 1, 2, 2, 3}, 2));
10+
}
11+
12+
[Fact]
13+
public void TopKFrequent2() {
14+
Assert.Equal(new int[] {1}, new Solution().TopKFrequent(new int[] {1}, 1));
15+
}
16+
}
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace LeetCodeNet.G0301_0400.S0394_decode_string {
2+
3+
using Xunit;
4+
5+
public class SolutionTest {
6+
[Fact]
7+
public void DecodeString() {
8+
Assert.Equal("aaabcbc", new Solution().DecodeString("3[a]2[bc]"));
9+
}
10+
11+
[Fact]
12+
public void DecodeString2() {
13+
Assert.Equal("accaccacc", new Solution().DecodeString("3[a2[c]]"));
14+
}
15+
16+
[Fact]
17+
public void DecodeString3() {
18+
Assert.Equal("abcabccdcdcdef", new Solution().DecodeString("2[abc]3[cd]ef"));
19+
}
20+
21+
[Fact]
22+
public void DecodeString4() {
23+
Assert.Equal("abccdcdcdxyz", new Solution().DecodeString("abc3[cd]xyz"));
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)