Skip to content

Commit 84be1ce

Browse files
authored
Added tasks 392-918
1 parent 6c848fd commit 84be1ce

File tree

22 files changed

+991
-0
lines changed

22 files changed

+991
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace LeetCodeNet.G0301_0400.S0392_is_subsequence {
2+
3+
using System;
4+
using Xunit;
5+
6+
public class SolutionTest {
7+
[Fact]
8+
public void IsSubsequence() {
9+
Assert.True(new Solution().IsSubsequence("abc", "ahbgdc"));
10+
}
11+
12+
[Fact]
13+
public void IsSubsequence2Test() {
14+
Assert.False(new Solution().IsSubsequence("axc", "ahbgdc"));
15+
}
16+
}
17+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace LeetCodeNet.G0401_0500.S0427_construct_quad_tree {
2+
3+
using System;
4+
using Xunit;
5+
6+
public class SolutionTest {
7+
[Fact]
8+
public void Construct() {
9+
string expectedOutput = "[0,1][1,0][1,1][1,1][1,0]";
10+
Assert.Equal(expectedOutput, new Solution().Construct(new int[][] {new int[] {0, 1}, new int[] {1, 0}}).ToString());
11+
}
12+
13+
[Fact]
14+
public void Construct2() {
15+
string expectedOutput = "[0,1][1,1][0,1][1,1][1,0]";
16+
Assert.Equal(expectedOutput,
17+
new Solution()
18+
.Construct(
19+
new int[][] {
20+
new int[] {1, 1, 1, 1, 0, 0, 0, 0},
21+
new int[] {1, 1, 1, 1, 0, 0, 0, 0},
22+
new int[] {1, 1, 1, 1, 1, 1, 1, 1},
23+
new int[] {1, 1, 1, 1, 1, 1, 1, 1},
24+
new int[] {1, 1, 1, 1, 0, 0, 0, 0},
25+
new int[] {1, 1, 1, 1, 0, 0, 0, 0},
26+
new int[] {1, 1, 1, 1, 0, 0, 0, 0},
27+
new int[] {1, 1, 1, 1, 0, 0, 0, 0}
28+
})
29+
.ToString());
30+
}
31+
}
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace LeetCodeNet.G0401_0500.S0433_minimum_genetic_mutation {
2+
3+
using Xunit;
4+
5+
public class SolutionTest {
6+
[Fact]
7+
public void MinMutation() {
8+
Assert.Equal(1, new Solution().MinMutation("AACCGGTT", "AACCGGTA", new string[] {"AACCGGTA"}));
9+
}
10+
11+
[Fact]
12+
public void MinMutation2() {
13+
Assert.Equal(2,
14+
new Solution()
15+
.MinMutation(
16+
"AACCGGTT",
17+
"AAACGGTA",
18+
new string[] {"AACCGGTA", "AACCGCTA", "AAACGGTA"}));
19+
}
20+
21+
[Fact]
22+
public void MinMutation3() {
23+
Assert.Equal(3,
24+
new Solution()
25+
.MinMutation(
26+
"AAAAACCC",
27+
"AACCCCCC",
28+
new string[] {"AAAACCCC", "AAACCCCC", "AACCCCCC"}));
29+
}
30+
}
31+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
namespace LeetCodeNet.G0401_0500.S0452_minimum_number_of_arrows_to_burst_balloons {
2+
3+
using System;
4+
using System.Linq;
5+
using System.Collections.Generic;
6+
using System.Text.RegularExpressions;
7+
using Xunit;
8+
9+
public static class CommonUtils {
10+
public static int[][] ConvertLeetCode2DArrayInputToArray(string input) {
11+
string[] rawPairs = input.TrimStart('[').TrimEnd(']').Split("],[", StringSplitOptions.RemoveEmptyEntries);
12+
List<int[]> result = new List<int[]>();
13+
foreach (string pair in rawPairs) {
14+
// Split each pair by comma
15+
string[] numbers = pair.Split(',');
16+
if (numbers.Length == 2) {
17+
int[] intArray = new int[2];
18+
if (int.TryParse(numbers[0], out intArray[0]) && int.TryParse(numbers[1], out intArray[1])) {
19+
result.Add(intArray);
20+
} else {
21+
throw new FormatException($"Invalid number format in pair: {pair}");
22+
}
23+
} else {
24+
throw new FormatException($"Invalid pair format: {pair}");
25+
}
26+
}
27+
return result.ToArray();
28+
}
29+
}
30+
31+
public class SolutionTest {
32+
[Fact]
33+
public void FindMinArrowShots() {
34+
int[][] points =
35+
CommonUtils.ConvertLeetCode2DArrayInputToArray(
36+
"[10,16],[2,8],[1,6],[7,12]");
37+
Assert.Equal(2, new Solution().FindMinArrowShots(points));
38+
}
39+
40+
[Fact]
41+
public void FindMinArrowShots2() {
42+
int[][] points =
43+
CommonUtils.ConvertLeetCode2DArrayInputToArray(
44+
"[1,2],[3,4],[5,6],[7,8]");
45+
Assert.Equal(4, new Solution().FindMinArrowShots(points));
46+
}
47+
48+
[Fact]
49+
public void FindMinArrowShots3() {
50+
int[][] points =
51+
CommonUtils.ConvertLeetCode2DArrayInputToArray(
52+
"[1,2],[2,3],[3,4],[4,5]");
53+
Assert.Equal(2, new Solution().FindMinArrowShots(points));
54+
}
55+
}
56+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace LeetCodeNet.G0501_0600.S0502_ipo {
2+
3+
using System;
4+
using Xunit;
5+
6+
public class SolutionTest {
7+
[Fact] public void FindMaximizedCapital() {
8+
Assert.Equal(4, new Solution().FindMaximizedCapital(2, 0, new int[] {1, 2, 3}, new int[] {0, 1, 1}));
9+
}
10+
11+
[Fact] public void FindMaximizedCapital2() {
12+
Assert.Equal(6, new Solution().FindMaximizedCapital(3, 0, new int[] {1, 2, 3}, new int[] {0, 1, 2}));
13+
}
14+
}
15+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace LeetCodeNet.G0901_1000.S0909_snakes_and_ladders {
2+
3+
using System;
4+
using Xunit;
5+
6+
public class SolutionTest {
7+
[Fact]
8+
public void SnakesAndLadders() {
9+
Assert.Equal(4,
10+
new Solution()
11+
.SnakesAndLadders(
12+
new int[][] {
13+
new int[] {-1, -1, -1, -1, -1, -1},
14+
new int[] {-1, -1, -1, -1, -1, -1},
15+
new int[] {-1, -1, -1, -1, -1, -1},
16+
new int[] {-1, 35, -1, -1, 13, -1},
17+
new int[] {-1, -1, -1, -1, -1, -1},
18+
new int[] {-1, 15, -1, -1, -1, -1}
19+
}));
20+
}
21+
22+
[Fact]
23+
public void SnakesAndLadders2() {
24+
Assert.Equal(1, new Solution().SnakesAndLadders(new int[][] {new int[] {-1, -1}, new int[] {-1, 3}}));
25+
}
26+
}
27+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace LeetCodeNet.G0901_1000.S0918_maximum_sum_circular_subarray {
2+
3+
using System;
4+
using Xunit;
5+
6+
public class SolutionTest {
7+
[Fact]
8+
public void MaxSubarraySumCircular() {
9+
Assert.Equal(3, new Solution().MaxSubarraySumCircular(new int[] {1, -2, 3, -2}));
10+
}
11+
12+
[Fact]
13+
public void MaxSubarraySumCircular2() {
14+
Assert.Equal(10, new Solution().MaxSubarraySumCircular(new int[] {5, -3, 5}));
15+
}
16+
17+
[Fact]
18+
public void MaxSubarraySumCircular3() {
19+
Assert.Equal(-2, new Solution().MaxSubarraySumCircular(new int[] {-3, -2, -3}));
20+
}
21+
}
22+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace LeetCodeNet.G0301_0400.S0392_is_subsequence {
2+
3+
// #Easy #String #Dynamic_Programming #Two_Pointers #LeetCode_75_Two_Pointers
4+
// #Dynamic_Programming_I_Day_19 #Level_1_Day_2_String #Udemy_Two_Pointers
5+
// #Top_Interview_150_Two_Pointers #2025_07_18_Time_0_ms_(100.00%)_Space_41.56_MB_(66.80%)
6+
7+
public class Solution {
8+
public bool IsSubsequence(string s, string t) {
9+
int i = 0;
10+
int j = 0;
11+
int n = t.Length;
12+
int m = s.Length;
13+
if (m == 0) {
14+
return true;
15+
}
16+
while (j < n) {
17+
if (s[i] == t[j]) {
18+
i++;
19+
if (i == m) {
20+
return true;
21+
}
22+
}
23+
j++;
24+
}
25+
return false;
26+
}
27+
}
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
392\. Is Subsequence
2+
3+
Easy
4+
5+
Given two strings `s` and `t`, return `true` _if_ `s` _is a **subsequence** of_ `t`_, or_ `false` _otherwise_.
6+
7+
A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace"` is a subsequence of `"abcde"` while `"aec"` is not).
8+
9+
**Example 1:**
10+
11+
**Input:** s = "abc", t = "ahbgdc"
12+
13+
**Output:** true
14+
15+
**Example 2:**
16+
17+
**Input:** s = "axc", t = "ahbgdc"
18+
19+
**Output:** false
20+
21+
**Constraints:**
22+
23+
* `0 <= s.length <= 100`
24+
* <code>0 <= t.length <= 10<sup>4</sup></code>
25+
* `s` and `t` consist only of lowercase English letters.
26+
27+
**Follow up:** Suppose there are lots of incoming `s`, say <code>s<sub>1</sub>, s<sub>2</sub>, ..., s<sub>k</sub></code> where <code>k >= 10<sup>9</sup></code>, and you want to check one by one to see if `t` has its subsequence. In this scenario, how would you change your code?

0 commit comments

Comments
 (0)