package leetcode;

/**
 * https://leetcode.com/problems/find-smallest-letter-greater-than-target/description/
 */
public class Problem744 {
    public char nextGreatestLetter(char[] letters, char target) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem744 prob = new Problem744();
        System.out.println(prob.nextGreatestLetter(new char[]{'c', 'f', 'j'}, 'a')); // c
        System.out.println(prob.nextGreatestLetter(new char[]{'c', 'f', 'j'}, 'c')); // f
        System.out.println(prob.nextGreatestLetter(new char[]{'c', 'f', 'j'}, 'd')); // f
        System.out.println(prob.nextGreatestLetter(new char[]{'c', 'f', 'j'}, 'g')); // j
        System.out.println(prob.nextGreatestLetter(new char[]{'c', 'f', 'j'}, 'j')); // c
        System.out.println(prob.nextGreatestLetter(new char[]{'c', 'f', 'j'}, 'k')); // c
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -237,669 +237,371 @@
     
-// TODO%0A        return 0
+int index = Arrays.binarySearch(letters, target)
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem744 prob = new Problem744();%0A        System.out.println(prob.nextGreatestLetter(new char%5B%5D%7B'c', 'f', 'j'%7D, 'a')); // c%0A        System.out.println(prob.nextGreatestLetter(new char%5B%5D%7B'c', 'f', 'j'%7D, 'c')); // f%0A        System.out.println(prob.nextGreatestLetter(new char%5B%5D%7B'c', 'f', 'j'%7D, 'd')); // f%0A        System.out.println(prob.nextGreatestLetter(new char%5B%5D%7B'c', 'f', 'j'%7D, 'g')); // j%0A        System.out.println(prob.nextGreatestLetter(new char%5B%5D%7B'c', 'f', 'j'%7D, 'j')); // c%0A        System.out.println(prob.nextGreatestLetter(new char%5B%5D%7B'c', 'f', 'j'%7D, 'k')); // c
+if (index %3E= 0) %7B%0A            index = (index + 1) %25 letters.length;%0A            while (letters%5Bindex%5D == target) %7B%0A                index = (index + 1) %25 letters.length;%0A            %7D%0A            return letters%5Bindex%5D;%0A        %7D%0A        index = (-index - 1) %25 letters.length;%0A        return letters%5Bindex%5D;
 %0A   

Solve problem 744