Obvious XOR Java runtime - O(N) space - O(1)


  • 0
    I
    public class Solution {
        public int singleNumber(int[] nums) {
            int res = 0;
            for(int i = 0; i < nums.length; i++) {
                res ^= nums[i];
            }
            return res;
        }
    }

Log in to reply
 

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