diff --git a/problems/0383.赎金信.md b/problems/0383.赎金信.md index d1594015..75b31698 100644 --- a/problems/0383.赎金信.md +++ b/problems/0383.赎金信.md @@ -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)