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



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] 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 |