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
- 맥북
- 파이썬
- 코로나19
- ChatGPT
- 자연어처리
- 백준
- github
- SW Expert Academy
- dacon
- AI 경진대회
- 금융문자분석경진대회
- Baekjoon
- 편스토랑 우승상품
- 더현대서울 맛집
- ubuntu
- 캐치카페
- leetcode
- hackerrank
- gs25
- 프로그래머스
- Real or Not? NLP with Disaster Tweets
- 데이콘
- 편스토랑
- Docker
- PYTHON
- 프로그래머스 파이썬
- Git
- Kaggle
- 우분투
- programmers
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 744. Find Smallest Letter Greater Than Target (Python) 본문
Programming/코딩 1일 1문제
[leetCode] 744. Find Smallest Letter Greater Than Target (Python)
솜씨좋은장씨 2020. 12. 5. 17:12728x90
반응형
Given a list of sorted characters letters containing only lowercase letters, and given a target letter target, find the smallest element in the list that is larger than the given target.
Letters also wrap around. For example, if the target is target = 'z' and letters = ['a', 'b'], the answer is 'a'.
Examples:
Input:
letters = ["c", "f", "j"]
target = "a"
Output: "c"
Input:
letters = ["c", "f", "j"]
target = "c"
Output: "f"
Input:
letters = ["c", "f", "j"]
target = "d"
Output: "f"
Input:
letters = ["c", "f", "j"]
target = "g"
Output: "j"
Input:
letters = ["c", "f", "j"]
target = "j"
Output: "c"
Input:
letters = ["c", "f", "j"]
target = "k"
Output: "c"
Note:
- letters has a length in range [2, 10000].
- letters consists of lowercase letters, and contains at least 2 unique letters.
- target is a lowercase letter.
Solution
class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
answer = letters[0]
for i in range(len(letters)):
if letters[i] > target:
answer = letters[i]
break
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 1588. Sum of All Odd Length Subarrays (Python) (0) | 2020.12.07 |
---|---|
[leetCode] 1436. Destination City (Python) (0) | 2020.12.06 |
[leetCode] 82. Remove Duplicates from Sorted List II (Python) (0) | 2020.12.02 |
[leetCode] 83. Remove Duplicates from Sorted List (Python) (0) | 2020.12.01 |
[leetCode] 148. Sort List (Python) (0) | 2020.11.29 |
Comments