Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 캐치카페
- Real or Not? NLP with Disaster Tweets
- 코로나19
- programmers
- 자연어처리
- hackerrank
- 더현대서울 맛집
- gs25
- PYTHON
- Kaggle
- leetcode
- 프로그래머스 파이썬
- ChatGPT
- 맥북
- 우분투
- 프로그래머스
- AI 경진대회
- dacon
- github
- 금융문자분석경진대회
- Baekjoon
- 편스토랑 우승상품
- 파이썬
- ubuntu
- Docker
- 데이콘
- SW Expert Academy
- Git
- 편스토랑
- 백준
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 392. Is Subsequence (Python) 본문
728x90
반응형
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
'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 |
Comments