Using advantage of sorted array, Java o(n)
\n# Approach\n Describe your approach to solving the problem. \nAs the given array is sorted, if the element is present twice,we can simply check by checking th
\n# Approach\n<!-- Describe your approach to solving the problem. -->\nAs the given array is sorted, if the element is present twice,we can simply check by checking the element with i+1 element, if twice the element found we can skip the next element, until the elements appearing twice we can search with i+=2, then if the element is not equal to i+1, then we return the element.\nWe have to make sure the i wont reach the out of index.\n# Complexity\n- Time complexity:\n- o(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n# Code\n```\nclass Solution {\n    public int singleNonDuplicate(int[] nums) {\n        for(int i=0;i<nums.length;i++)\n        {\n            if(i == nums.length-1)\n            {\n                return nums[i];\n            }\n            else\n            {\n                if(nums[i] == nums[i+1])\n                {\n                    if((i+1) != nums.length-1)\n                    {\n                        i++;\n                    }\n                }\n                else\n                {\n                    return nums[i];\n                }\n            }\n        }\n        return 0;\n    }\n}\n```
['Java']