Merge pull request #741 from andywang0607/383_rust

增加0383.赎金信Rust語言版本
This commit is contained in:
程序员Carl
2021-09-14 10:14:28 +08:00
committed by GitHub

View File

@ -315,6 +315,28 @@ func canConstruct(_ ransomNote: String, _ magazine: String) -> Bool {
}
```
Rust:
```rust
impl Solution {
pub fn can_construct(ransom_note: String, magazine: String) -> bool {
let baseChar = 'a';
let mut record = vec![0; 26];
for byte in magazine.bytes() {
record[byte as usize - baseChar as usize] += 1;
}
for byte in ransom_note.bytes() {
record[byte as usize - baseChar as usize] -= 1;
if record[byte as usize - baseChar as usize] < 0 {
return false;
}
}
return true;
}
}
```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)