Skip to content

Commit 0cd4725

Browse files
added "392. Is Subsequence"
1 parent fdc593b commit 0cd4725

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Solutions from [LeetCode](https://leetcode.com) on Dart.
1717
| 217. Contains Duplicate | [Link](https://leetcode.com/problems/contains-duplicate/) | [Link](./lib/easy/contains_duplicate.dart) |
1818
| 226. Invert Binary Tree | [Link](https://leetcode.com/problems/invert-binary-tree/) | [Link](./lib/easy/invert_binary_tree.dart) |
1919
| 342. Power of Four | [Link](https://leetcode.com/problems/power-of-four/) | [Link](./lib/easy/power_of_four.dart) |
20+
| 392. Is Subsequence | [Link](https://leetcode.com/problems/is-subsequence/) | [Link](./lib/easy/is_subsequence.dart) |
2021
| 414. Third Maximum Number | [Link](https://leetcode.com/problems/third-maximum-number/) | [Link](./lib/easy/third_maximum_number.dart) |
2122
| 796. Rotate String | [Link](https://leetcode.com/problems/rotate-string/) | [Link](./lib/easy/rotate_string.dart) |
2223
| 944. Delete Columns to Make Sorted | [Link](https://leetcode.com/problems/delete-columns-to-make-sorted/) | [Link](./lib/easy/delete_columns_to_make_sorted.dart) |

lib/easy/is_subsequence.dart

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
bool isSubsequence(String s, String t) {
3+
var sP = 0;
4+
var tP = 0;
5+
while (sP != s.length && tP != t.length) {
6+
if (s[sP] == t[tP]) {
7+
sP++;
8+
}
9+
tP++;
10+
}
11+
return sP == s.length;
12+
}
13+
}

test/easy/is_subsequence_test.dart

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'package:leetcode_dart/easy/is_subsequence.dart';
2+
import 'package:test/test.dart';
3+
4+
void main() {
5+
group(
6+
'Example tests',
7+
() {
8+
final isSub = Solution();
9+
test('true', () => isSub.isSubsequence('abc', 'ahbgdc'));
10+
test('false', () => isSub.isSubsequence('axc', 'ahbgdc'));
11+
},
12+
);
13+
}

0 commit comments

Comments
 (0)