Skip to content

Commit b0340b3

Browse files
committed
src/bin/ransom-note.rs
1 parent 7e6dfb2 commit b0340b3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/bin/ransom-note.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
fn main() {}
2+
3+
struct Solution;
4+
5+
impl Solution {
6+
pub fn can_construct(ransom_note: String, magazine: String) -> bool {
7+
let mut h = std::collections::HashMap::new();
8+
for i in magazine.bytes() {
9+
h.entry(i).and_modify(|x| *x += 1).or_insert(1);
10+
}
11+
12+
for i in ransom_note.bytes() {
13+
if let Some(x) = h.get_mut(&i) {
14+
if *x >= 1 {
15+
*x -= 1;
16+
continue;
17+
}
18+
}
19+
20+
return false;
21+
}
22+
23+
24+
true
25+
}
26+
}

0 commit comments

Comments
 (0)