Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Binary Tree
- 코딩테스트
- 코테
- two pointers
- 구현
- array
- greedy
- Class
- geometry
- 자바
- dynamic programming
- simulation
- Binary Search
- Data Structure
- java
- Number Theory
- bit manipulation
- Stack
- Counting
- implement
- sorting
- hash table
- SQL
- 파이썬
- Method
- Math
- database
- Tree
- string
- Matrix
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 744. Find Smallest Letter Greater Than Target 본문
1. Input
1) 배열의 요소가 문자 1개인 문자열 배열 letters
2) 문자 1개를 담은 문자열 변수 target
2. Output
1) 사전순으로 생각했을 때 letters에서 target보다 뒤에 나오는 문자 중 가장 작은 것
2) 없다면 letters[0]을 반환
3. Constraint
1) letters는 사전순으로 정렬되어 있다.
2) 2 <= letters.length <= 104
3) letters[i], target은 알파벳 소문자 1개가 담긴 문자열
4) letters에는 서로 다른 문자가 최소 2개가 있다.
4. Example
Input: letters = ["c","f","j"], target = "c" -> Output: “f”
Input: letters = ["x","x","y","y"], target = "z" -> Output: "x“
설명:
- c보다 뒤에 오는 것은 f와 j이고, 이중 가장 작은 것은 f이므로 “f”를 반환한다.
- letters의 모든 문자들이 z보다 뒤에 오는 것이 없으므로 letters의 가장 앞 문자인 “x”를 반환한다.
5. Code
1) 첫 코드(2022/07/19)
char c = letters[0];
for(int i=0 ; i<letters.length ; i++)
if(target<letters[i]){
c = letters[i]; break;
}
return c;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 762. Prime Number of Set Bits in Binary Representation (0) | 2022.12.07 |
---|---|
[LeetCode/Easy] 747. Largest Number At Least Twice of Others (0) | 2022.12.07 |
[LeetCode/Easy] 728. Self Dividing Numbers (0) | 2022.12.06 |
[LeetCode/Easy] 724. Find Pivot Index (0) | 2022.12.06 |
[LeetCode/Easy] 709. To Lower Case (0) | 2022.12.05 |