Java 8 Solution


  • 0
    A
    public class Solution {
        public int singleNumber(int[] nums) {
            if (nums == null) {
                return -1;
            }
            
            final int[] res = {0};
            
            Arrays.stream(nums).forEach(x -> res[0] ^= x);
    
            return res[0];
        }
    }
    

Log in to reply
 

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