20240728 Finished

This commit is contained in:
jackfiled 2024-07-28 12:01:08 +08:00
parent e4aa6c1c8f
commit 0fbc21599e
2 changed files with 34 additions and 1 deletions

View File

@ -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;

View 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]));
}
}