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
- 금융문자분석경진대회
- programmers
- Git
- github
- SW Expert Academy
- Real or Not? NLP with Disaster Tweets
- ChatGPT
- 파이썬
- 캐치카페
- 프로그래머스 파이썬
- 편스토랑
- AI 경진대회
- leetcode
- 맥북
- Kaggle
- 프로그래머스
- gs25
- 더현대서울 맛집
- Baekjoon
- ubuntu
- hackerrank
- dacon
- 데이콘
- 코로나19
- Docker
- 백준
- 편스토랑 우승상품
- PYTHON
- 자연어처리
- 우분투
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 925. Long Pressed Name (Python) 본문
728x90
반응형
Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times.
You examine the typed characters of the keyboard. Return True if it is possible that it was your friends name, with some characters (possibly none) being long pressed.
Example 1:
Input: name = "alex", typed = "aaleex"
Output: true
Explanation: 'a' and 'e' in 'alex' were long pressed.
Example 2:
Input: name = "saeed", typed = "ssaaedd"
Output: false
Explanation: 'e' must have been pressed twice, but it wasn't in the typed output.
Example 3:
Input: name = "leelee", typed = "lleeelee"
Output: true
Example 4:
Input: name = "laiden", typed = "laiden"
Output: true
Explanation: It's not necessary to long press any character.
Constraints:
- 1 <= name.length <= 1000
- 1 <= typed.length <= 1000
- The characters of name and typed are lowercase letters.
Solution
class Solution:
def isLongPressedName(self, name: str, typed: str) -> bool:
cnt = 0
answer = False
for i in range(len(typed)):
if cnt < len(name) and name[cnt] == typed[i]:
cnt = cnt + 1
elif i == 0 or typed[i] != typed[i-1]:
return answer
if cnt == len(name):
answer = True
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 1417. Reformat The String (Python) (0) | 2020.09.28 |
---|---|
[leetCode] 1051. Height Checker (Python) (0) | 2020.09.27 |
[leetCode] 686. Repeated String Match (Python) (0) | 2020.09.24 |
[leetCode] 1207. Unique Number of Occurrences (Python) (0) | 2020.09.23 |
[leetCode] 657. Robot Return to Origin (Python) (0) | 2020.09.22 |
Comments