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

Function find_the_difference

389-find-the-difference.rs:1–14  ·  view source on GitHub ↗
(s: String, t: String)

Source from the content-addressed store, hash-verified

1pub fn find_the_difference(s: String, t: String) -> char {
2 use std::collections::HashMap;
3 let mut chars_map = HashMap::new();
4 for c in s.chars() {
5 let counter = chars_map.entry(c).or_insert(0);
6 *counter += 1;
7 }
8 for c in t.chars() {
9 let counter = chars_map.entry(c).or_insert(0);
10 *counter -= 1;
11 }
12 chars_map.retain(|_, v| v == &-1);
13 *chars_map.keys().nth(0).unwrap()
14}
15
16fn main() {
17 let s = "abcd".to_string();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected