Skip to content

Commit 4e40ad0

Browse files
refactor 136
1 parent 7bc3121 commit 4e40ad0

File tree

1 file changed

+12
-5
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+12
-5
lines changed

src/main/java/com/fishercoder/solutions/_136.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66

77
/**136. Single Number
88
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.
1010
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
1321
*/
1422

1523
public class _136 {
@@ -28,8 +36,7 @@ public int singleNumber(int[] nums) {
2836
set.remove(i);
2937
}
3038
}
31-
Iterator<Integer> it = set.iterator();
32-
return it.next();
39+
return set.iterator().next();
3340
}
3441
}
3542

0 commit comments

Comments
 (0)