20240727 Finished
This commit is contained in:
parent
c88f7a8f79
commit
e4aa6c1c8f
|
@ -186,3 +186,4 @@ mod p295_find_median_from_data_stream;
|
||||||
mod p67_add_binary;
|
mod p67_add_binary;
|
||||||
mod p190_reverse_bits;
|
mod p190_reverse_bits;
|
||||||
mod p191_number_of_1_bits;
|
mod p191_number_of_1_bits;
|
||||||
|
mod p136_single_number;
|
32
src/problem/p136_single_number.rs
Normal file
32
src/problem/p136_single_number.rs
Normal 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]));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user