MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / single_number

Function single_number

136-single-number.rs:16–27  ·  view source on GitHub ↗
(nums: Vec<i32>)

Source from the content-addressed store, hash-verified

14// 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
15
16pub fn single_number(nums: Vec<i32>) -> i32 {
17 use std::collections::HashMap;
18 let mut kvm = HashMap::new();
19 for num in nums {
20 if !kvm.contains_key(&num) {
21 kvm.insert(num, true);
22 } else {
23 kvm.remove(&num);
24 }
25 }
26 *kvm.keys().nth(0).unwrap()
27}
28
29
30fn main() {

Callers

nothing calls this directly

Calls 2

insertMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected