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
- 맥북
- 백준
- 데이콘
- gs25
- 프로그래머스 파이썬
- Git
- Docker
- 파이썬
- 편스토랑 우승상품
- SW Expert Academy
- 더현대서울 맛집
- Real or Not? NLP with Disaster Tweets
- 편스토랑
- ChatGPT
- Kaggle
- Baekjoon
- programmers
- hackerrank
- 코로나19
- ubuntu
- 자연어처리
- 금융문자분석경진대회
- dacon
- 프로그래머스
- 우분투
- 캐치카페
- PYTHON
- github
- leetcode
- AI 경진대회
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