| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
- gs25
- 코로나19
- Docker
- programmers
- 백준
- 프로그래머스 파이썬
- 편스토랑 우승상품
- Real or Not? NLP with Disaster Tweets
- 자연어처리
- ubuntu
- Kaggle
- SW Expert Academy
- ChatGPT
- 금융문자분석경진대회
- Git
- 프로그래머스
- 우분투
- Baekjoon
- 편스토랑
- AI 경진대회
- leetcode
- 데이콘
- 파이썬
- 맥북
- PYTHON
- github
- dacon
- hackerrank
- 더현대서울 맛집
- 캐치카페
- Today
- Total
솜씨좋은장씨
[leetCode] 392. Is Subsequence (Python) 본문

Given a string s and a string t, check if s is subsequence of t.
A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ace" is a subsequence of "abcde" while "aec" is not).
Follow up:
If there are lots of incoming S, say S1, S2, ... , Sk where k >= 1B, and you want to check one by one to see if T has its subsequence. In this scenario, how would you change your code?
Credits:
Special thanks to @pbrother for adding this problem and creating all test cases.
Example 1:
Input: s = "abc", t = "ahbgdc"
Output: true
Example 2:
Input: s = "axc", t = "ahbgdc"
Output: false
Constraints:
- 0 <= s.length <= 100
- 0 <= t.length <= 10^4
- Both strings consists only of lowercase characters.
Solution
class Solution:
def isSubsequence(self, s: str, t: str) -> bool:
len_s = len(s)
if len_s == 0:
return True
cnt = 0
for val in t:
if val == s[cnt]:
cnt = cnt + 1
if cnt == len_s:
return True
break
return False



SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
| [leetCode] 344. Reverse String (Python) (0) | 2020.08.13 |
|---|---|
| [leetCode] 121. Best Time to Buy and Sell Stock (Python) (0) | 2020.08.13 |
| [leetCode] 916. Word Subsets (Python) (0) | 2020.08.09 |
| [leetCode] 551. Student Attendance Record I (Python) (0) | 2020.08.08 |
| [leetCode] 345. Reverse Vowels of a String (Python) (0) | 2020.08.07 |