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



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