java solution binary search tree


  • 0
    T

    class Solution {
    public int missingNumber(int[] nums) {
    Arrays.sort(nums);
    int start = 0;
    int end = nums.length - 1;
    while(start + 1 < end) {
    int mid = start + (end - start) / 2;
    if (nums[mid] == mid) {
    start = mid;
    } else {
    end = mid;
    }
    }
    if (nums[end] == end) {
    return end + 1;
    }
    if (nums[start] > start) {
    return start;
    }else {
    return start + 1;
    }
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.