package leetcode;

/**
 * https://leetcode.com/problems/single-element-in-a-sorted-array/
 */
public class Problem540 {
    public int singleNonDuplicate(int[] nums) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem540 prob = new Problem540();
        System.out.println(prob.singleNonDuplicate(new int[]{1, 1, 2, 3, 3, 4, 4, 8, 8})); // 2
        System.out.println(prob.singleNonDuplicate(new int[]{3, 3, 7, 7, 10, 11, 11})); // 10
    }
}

@@ -173,32 +173,892 @@
     
-// TODO%0A        return 0
+int i = 0;%0A        int j = nums.length - 1;%0A        while (i %3C j) %7B%0A            int tmpi = i;%0A            int tmpj = j;%0A            int mid = (i + j) / 2;%0A            if (mid + 1 %3C nums.length) %7B%0A                if (mid - 1 %3E= 0) %7B%0A                    if (nums%5Bmid%5D == nums%5Bmid - 1%5D) %7B%0A                        if ((mid - 1 - i) %25 2 != 0) %7B%0A                            j = mid;%0A                        %7D else %7B%0A                            i = mid;%0A                        %7D%0A                    %7D%0A                %7D%0A                if (nums%5Bmid%5D == nums%5Bmid + 1%5D) %7B%0A                    if ((j - mid + 1) %25 2 != 0) %7B%0A                        i = mid;%0A                    %7D else %7B%0A                        j = mid;%0A                    %7D%0A                %7D%0A            %7D%0A            if (tmpi == i && tmpj == j) %7B%0A                return nums%5Bmid%5D;%0A            %7D%0A        %7D%0A        return nums%5Bi%5D
 ;%0A  
@@ -1151,16 +1151,18 @@
 m540();%0A
+//
         
@@ -1249,16 +1249,18 @@
 ); // 2%0A
+//
         
@@ -1345,16 +1345,200 @@
 ; // 10%0A
+        System.out.println(prob.singleNonDuplicate(new int%5B%5D%7B1, 3, 3, 7, 7, 11, 11%7D)); // 1%0A        System.out.println(prob.singleNonDuplicate(new int%5B%5D%7B1, 1, 3, 3, 7, 7, 11%7D)); // 11%0A
     %7D%0A%7D%0A

Update problem 540