https://leetcode.com/problems/single-number/
Example 1:
Input: nums = [2,2,1] Output: 1
package pep.Day63;
public class LeetCode_136_Single_Number {
public static void main(String[] args) {
System.out.println(singleNumber(new int[]{2, 2, 1}));
}
public static int singleNumber(int[] nums) {
int ans = 0;
for (int i : nums) {
ans = ans ^ i;
}
return ans;
}
}

No comments:
Post a Comment