Skip to content

Commit d4bec78

Browse files
committed
single number
1 parent 52ee2ef commit d4bec78

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

260.single-number-iii.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* @lc app=leetcode id=260 lang=rust
3+
*
4+
* [260] Single Number III
5+
*/
6+
7+
// @lc code=start
8+
impl Solution {
9+
pub fn single_number(nums: Vec<i32>) -> Vec<i32> {
10+
let mut xor_tot = 0;
11+
for num in nums.iter() {
12+
xor_tot ^= num;
13+
}
14+
15+
xor_tot &= - xor_tot;
16+
17+
let mut a = 0;
18+
let mut b = 0;
19+
20+
for num in nums {
21+
if xor_tot & num == 0 {
22+
a ^= num;
23+
} else {
24+
b ^= num;
25+
}
26+
}
27+
28+
vec![a, b]
29+
}
30+
}
31+
// @lc code=end
32+

0 commit comments

Comments
 (0)