Java O(n)t O(1)s


  • 0
    R
    public class Solution {
        public int singleNumber(int[] nums) {
            if(nums.length==0) return -1;
            int ans=nums[0];
            for(int i=1;i<nums.length;i++) ans^=nums[i];
            return ans;
        }
    }
    

Log in to reply
 

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