Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LeetCode URL: https://leetcode.com/problems/single-number/
- /**
- * XOR of all numbers. XOR result is the answer.
- *
- * Time Complexity: O(N)
- *
- * Space Complexity: O(1)
- *
- * N = Length of the input array.
- */
- class Solution {
- public int singleNumber(int[] nums) throws IllegalArgumentException {
- if (nums == null || nums.length == 0) {
- throw new IllegalArgumentException("Invalid Input");
- }
- int result = 0;
- for (int num : nums) {
- result ^= num;
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement