✅ 0 ms | simple java solution | 🚀100% faster
\n\n# Code\n\nclass Solution {\n    public int singleNonDuplicate(int[] nums) {\n        if(nums.length == 1) return nums[0];\n        //create the search space
\n\n# Code\n```\nclass Solution {\n    public int singleNonDuplicate(int[] nums) {\n        if(nums.length == 1) return nums[0];\n        //create the search space\n        int low = 0;\n        int high = nums.length-1;\n        while(low <= high){\n            //find the middle index;\n            int mid = low+(high - low)/2;\n            if(mid-1 >=0 && nums[mid] == nums[mid-1]){\n                mid--;\n                int left_space = mid - low;\n                int right_space = high - (mid - 1);\n                if(left_space%2 != 0){\n                    high = mid - 1;\n                }\n                else if(right_space%2 != 0){\n                    low = mid + 2;\n                }\n            }\n            else if(mid+1 <= nums.length-1 && nums[mid] == nums[mid+1]){\n                mid++;\n                int left_space = (mid-1) - low;\n                int right_space = high - mid;\n                if(left_space%2 != 0){\n                    high = mid - 2;\n                }\n                else if(right_space%2 != 0){\n                    low = mid + 1;\n                }\n            }\n            else\n                return nums[mid];\n        }\n        return -1;\n    }\n}\n```
['Java']