20240728 Finished
This commit is contained in:
parent
e4aa6c1c8f
commit
0fbc21599e
|
@ -186,4 +186,5 @@ mod p295_find_median_from_data_stream;
|
|||
mod p67_add_binary;
|
||||
mod p190_reverse_bits;
|
||||
mod p191_number_of_1_bits;
|
||||
mod p136_single_number;
|
||||
mod p136_single_number;
|
||||
mod p137_single_number_ii;
|
32
src/problem/p137_single_number_ii.rs
Normal file
32
src/problem/p137_single_number_ii.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* [137] Single Number II
|
||||
*/
|
||||
pub struct Solution {}
|
||||
|
||||
|
||||
// submission codes start here
|
||||
|
||||
impl Solution {
|
||||
pub fn single_number(nums: Vec<i32>) -> i32 {
|
||||
let (mut a, mut b) = (0, 0);
|
||||
|
||||
for i in nums {
|
||||
b = !a & (b ^ i);
|
||||
a = !b & ( a ^ i);
|
||||
}
|
||||
|
||||
b
|
||||
}
|
||||
}
|
||||
|
||||
// submission codes end
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_137() {
|
||||
assert_eq!(1, Solution::single_number(vec![1, 2, 2, 2]));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user