Simple Solution


  • 0
    A
    public class Solution {
        public int singleNonDuplicate(int[] nums) {
            boolean singleSpan=true;
            for(int i=1;i<nums.length;i++){
                int lastOne = nums[i-1];
                int num = nums[i];
                if(lastOne==num){
                    singleSpan=false;
                }
                else{
                    if(singleSpan) {
                        return lastOne;
                    }
                    singleSpan=true;
                }
            }
            return nums[nums.length-1];
        }
    }
    

Log in to reply
 

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