java.lang.Object
g0701_0800.s0744_find_smallest_letter_greater_than_target.Solution

public class Solution extends java.lang.Object
744 - Find Smallest Letter Greater Than Target.

Easy

Given a characters array letters that is sorted in non-decreasing order and a character target, return the smallest character in the array that is larger than target.

Note that the letters wrap around.

  • For example, if target == 'z' and letters == ['a', 'b'], the answer is 'a'.

Example 1:

Input: letters = [“c”,“f”,“j”], target = “a”

Output: “c”

Example 2:

Input: letters = [“c”,“f”,“j”], target = “c”

Output: “f”

Example 3:

Input: letters = [“c”,“f”,“j”], target = “d”

Output: “f”

Constraints:

  • 2 <= letters.length <= 104
  • letters[i] is a lowercase English letter.
  • letters is sorted in non-decreasing order.
  • letters contains at least two different characters.
  • target is a lowercase English letter.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    char
    nextGreatestLetter(char[] letters, char target)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • nextGreatestLetter

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