O(logN) time , O(1) space , easy to understand.
\nclass Solution {\n    public int singleNonDuplicate(int[] nums) {\n        int low=0;\n        int high=nums.length;\n        while(low<=high){\n            i
```\nclass Solution {\n    public int singleNonDuplicate(int[] nums) {\n        int low=0;\n        int high=nums.length;\n        while(low<=high){\n            int mid=low+(high-low)/2;\n            if(mid-1>=0 && nums[mid]==nums[mid-1]){\n                // this is second occurance\n                if(mid%2==1){\n                    // it must be odd if all numbers are paired in left, then unpaired element must found in right\n                    low=mid+1;\n                }else{\n                    // if it is not odd then element in in left\n                    high=mid-1;\n                }\n            }else if(mid+1< nums.length && nums[mid]==nums[mid+1]){\n                // this is first occurance\n                if(mid%2==0){\n                    low=mid+1;\n                }else{\n                    high=mid-1;\n                }\n            }else{\n                return nums[mid];\n            }\n        }\n        return -1;\n    }\n}\n```
[]