Skip to content

Commit b15bfb6

Browse files
committed
src/bin/find-the-difference.rs
1 parent c141371 commit b15bfb6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/bin/find-the-difference.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
fn main() {}
2+
3+
struct Solution;
4+
5+
impl Solution {
6+
pub fn find_the_difference(s: String, t: String) -> char {
7+
let mut h = vec![0u8; 26];
8+
9+
for i in s.bytes() {
10+
h[(i - b'a') as usize] += 1;
11+
}
12+
13+
for i in t.bytes() {
14+
if h[(i - b'a') as usize] == 0 {
15+
return i as char;
16+
}
17+
18+
h[(i - b'a') as usize] -= 1;
19+
}
20+
21+
'a'
22+
}
23+
}

0 commit comments

Comments
 (0)