• 문제 링크
Find Smallest Letter Greater Than Target - LeetCode
Can you solve this real interview question? Find Smallest Letter Greater Than Target - You are given an array of characters letters that is sorted in non-decreasing order, and a character target. There are at least two different characters in letters. Retu
leetcode.com
• 풀이 코드
public class Solution {
public char nextGreatestLetter(char[] letters, char target) {
int l = 0, r = letters.length - 1, i = -1;
while (l <= r) {
int m = l + (r - l) / 2;
if (letters[m] > target) {
r = m - 1;
i = m;
} else l = m + 1;
}
return i == -1 ? letters[0] : letters[i];
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 747. Largest Number At Least Twice of Others - Java (0) | 2026.10.09 |
|---|---|
| [LeetCode] 746. Min Cost Climbing Stairs - Java (0) | 2026.10.08 |
| [LeetCode] 733. Flood Fill - Java (0) | 2026.10.06 |
| [LeetCode] 728. Self Dividing Numbers - Java (0) | 2026.10.05 |
| [LeetCode] 724. Find Pivot Index - Java (0) | 2026.10.04 |
댓글