java.lang.Object
g0701_0800.s0744_find_smallest_letter_greater_than_target.Solution

public class Solution extends Object
744 - Find Smallest Letter Greater Than Target.<p>Easy</p> <p>Given a characters array <code>letters</code> that is sorted in <strong>non-decreasing</strong> order and a character <code>target</code>, return <em>the smallest character in the array that is larger than</em> <code>target</code>.</p> <p><strong>Note</strong> that the letters wrap around.</p> <ul> <li>For example, if <code>target == 'z'</code> and <code>letters == ['a', 'b']</code>, the answer is <code>'a'</code>.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> letters = [&ldquo;c&rdquo;,&ldquo;f&rdquo;,&ldquo;j&rdquo;], target = &ldquo;a&rdquo;</p> <p><strong>Output:</strong> &ldquo;c&rdquo;</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> letters = [&ldquo;c&rdquo;,&ldquo;f&rdquo;,&ldquo;j&rdquo;], target = &ldquo;c&rdquo;</p> <p><strong>Output:</strong> &ldquo;f&rdquo;</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> letters = [&ldquo;c&rdquo;,&ldquo;f&rdquo;,&ldquo;j&rdquo;], target = &ldquo;d&rdquo;</p> <p><strong>Output:</strong> &ldquo;f&rdquo;</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= letters.length <= 10<sup>4</sup></code></li> <li><code>letters[i]</code> is a lowercase English letter.</li> <li><code>letters</code> is sorted in <strong>non-decreasing</strong> order.</li> <li><code>letters</code> contains at least two different characters.</li> <li><code>target</code> is a lowercase English letter.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • nextGreatestLetter

      public char nextGreatestLetter(char[] letters, char target)