Java Binary Search | Beats 100% | Most Intutive | Explanation Using Image
Intution: keep dividing your array in two halves and check in which half there are odd number of elements...that will be your required part.\n\n\n\n\n\n\n\n\ncl
**Intution:** keep dividing your array in two halves and check in which half there are odd number of elements...that will be your required part.\n\n\n\n\n![image](https://assets.leetcode.com/users/images/f7fc208d-13da-423c-8069-e50c7c810c0d_1637377156.442444.jpeg)\n\n\n```\nclass Solution {\n    public int singleNonDuplicate(int[] nums) {\n        if(nums.length==1) return nums[0];\n        int l = 0;\n        int h = nums.length-1;\n        \n        while(l<h){\n            int mid = l+(h-l)/2;      // divide the array\n            \n            if(nums[mid]==nums[mid+1]) mid = mid-1;      //two same elements should be in same half\n            \n            if((mid-l+1)%2!=0) h = mid;            // checking the length of left half. If its is odd then update ur right pointer to mid\n            \n            else l = mid+1;    // else your right half will be odd then update your left pointer to mid+1\n        }\n        \n        return nums[l];     //left pointer will have the answer at last\n    }\n}\n```\n
['Binary Tree', 'Java']