-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
136.java
34 lines (32 loc) · 979 Bytes
/
136.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public int singleNumber(int[] nums) {
int x = 0;
for (int a : nums) {
x = x ^ a;
}
return x;
}
}
__________________________________________________________________________________________________
sample 35152 kb submission
class Solution {
public int singleNumber(int[] nums) {
HashMap<Integer, Integer> map = new HashMap<>();
for(int i:nums){
if(!map.containsKey(i)){
map.put(i,1);
}
else{
map.replace(i, map.get(i)+1);
}
}
int result = 0;
for(int j:nums){
if(map.get(j) == 1) result = j;
}
return result;
}
}
__________________________________________________________________________________________________