File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change 6
6
7
7
/**136. Single Number
8
8
9
- Given an array of integers, every element appears twice except for one. Find that single one.
9
+ Given a non-empty array of integers, every element appears twice except for one. Find that single one.
10
10
11
- Note:
12
- Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
11
+ Note:
12
+ Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
13
+
14
+ Example 1:
15
+ Input: [2,2,1]
16
+ Output: 1
17
+
18
+ Example 2:
19
+ Input: [4,1,2,1,2]
20
+ Output: 4
13
21
*/
14
22
15
23
public class _136 {
@@ -28,8 +36,7 @@ public int singleNumber(int[] nums) {
28
36
set .remove (i );
29
37
}
30
38
}
31
- Iterator <Integer > it = set .iterator ();
32
- return it .next ();
39
+ return set .iterator ().next ();
33
40
}
34
41
}
35
42
You can’t perform that action at this time.
0 commit comments