Skip to content

Commit aedaf89

Browse files
committed
D. J.:
- Added the leetcode problem and solution for 392 Is Subsequence
1 parent 21fbaf4 commit aedaf89

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This repository contains awesome LeetCode problems and solutions written in Pyth
1515
- [125 Valid Palindrome](https://leetcode.com/problems/valid-palindrome/description/)
1616
- [169 Majority Element](https://leetcode.com/problems/majority-element/description/)
1717
- [189 Rotate Array](https://leetcode.com/problems/rotate-array/description/)
18+
- [392 Is Subsequence](https://leetcode.com/problems/is-subsequence/description/)
1819

1920
## Development 🔧
2021

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def isSubsequence(self, s: str, t: str) -> bool:
3+
"""
4+
Given two strings s and t, return true if s is a subsequence of t, or false otherwise.
5+
6+
A subsequence of a string is a new string that is formed from the original string by deleting some (can be none)
7+
of the characters without disturbing the relative positions of the remaining characters.
8+
(i.e., "ace" is a subsequence of "abcde" while "aec" is not).
9+
"""
10+
left_s, right_s = 0, len(s)
11+
left_t, right_t = 0, len(t)
12+
while left_s < right_s and left_t < right_t:
13+
if s[left_s] == t[left_t]:
14+
left_s += 1
15+
left_t += 1
16+
return left_s == right_s

tests/test_392_is_subsequence.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
3+
from awesome_python_leetcode._392_is_subsequence import Solution
4+
5+
6+
@pytest.mark.parametrize(
7+
argnames=["s", "t", "expected"],
8+
argvalues=[
9+
("abc", "ahbgdc", True),
10+
("axc", "ahbgdc", False),
11+
],
12+
)
13+
def test_func(s: str, t: str, expected: bool):
14+
is_subsequence = Solution().isSubsequence(s, t)
15+
assert is_subsequence == expected

0 commit comments

Comments
 (0)