20240727 Finished

This commit is contained in:
jackfiled 2024-07-27 10:57:47 +08:00
parent c88f7a8f79
commit e4aa6c1c8f
2 changed files with 34 additions and 1 deletions

View File

@ -185,4 +185,5 @@ mod p373_find_k_pairs_with_smallest_sums;
mod p295_find_median_from_data_stream;
mod p67_add_binary;
mod p190_reverse_bits;
mod p191_number_of_1_bits;
mod p191_number_of_1_bits;
mod p136_single_number;

View File

@ -0,0 +1,32 @@
/**
* [136] Single Number
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn single_number(nums: Vec<i32>) -> i32 {
let mut result = 0;
for i in nums {
result ^= i;
}
result
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_136() {
assert_eq!(1, Solution::single_number(vec![1, 2, 2]));
assert_eq!(1, Solution::single_number(vec![1]));
}
}