mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
增加0383.赎金信Rust語言版本
Note: - leetcode提交通過
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user