Skip to content

Commit 91a75d4

Browse files
committed
Solution for: single number
1 parent 040eba2 commit 91a75d4

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/leetcode/SingleNumber.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ public static void main(String[] args){
1010
}
1111

1212
public int singleNumber(int[] nums) {
13-
Map<Integer,Integer> map = new HashMap<>();
14-
for(int i: nums){
15-
if(map.containsKey(i))
16-
map.put(i, map.get(i)+1);
17-
else
18-
map.put(i, 1);
19-
}
20-
for(Map.Entry e: map.entrySet()){
21-
if((int)e.getValue()==1)
22-
return (int)e.getKey();
23-
}
24-
return 0;
25-
}
13+
Map<Integer,Integer> map = new HashMap<>();
14+
for(int i: nums){
15+
if(map.containsKey(i))
16+
map.put(i, map.get(i)+1);
17+
else
18+
map.put(i, 1);
19+
}
20+
for(Map.Entry e: map.entrySet()){
21+
if((int)e.getValue()==1)
22+
return (int)e.getKey();
23+
}
24+
return 0;
25+
}
2626
}

0 commit comments

Comments
 (0)