From 33fdd706765de8d794af88b6d2681909f855a1c6 Mon Sep 17 00:00:00 2001 From: YiChih Wang Date: Sun, 12 Sep 2021 12:19:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A00242.=E6=9C=89=E6=95=88?= =?UTF-8?q?=E7=9A=84=E5=AD=97=E6=AF=8D=E5=BC=82=E4=BD=8D=E8=AF=8DRust?= =?UTF-8?q?=E8=AA=9E=E8=A8=80=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note: - leetcode提交測試通過 --- problems/0242.有效的字母异位词.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/problems/0242.有效的字母异位词.md b/problems/0242.有效的字母异位词.md index 3416ac06..0828d360 100644 --- a/problems/0242.有效的字母异位词.md +++ b/problems/0242.有效的字母异位词.md @@ -256,6 +256,25 @@ class Solution { } ``` +Rust: +```rust +impl Solution { + pub fn is_anagram(s: String, t: String) -> bool { + let mut record = vec![0; 26]; + + let baseChar = 'a'; + + for byte in s.bytes() { + record[byte as usize - baseChar as usize] += 1; + } + for byte in t.bytes() { + record[byte as usize - baseChar as usize] -= 1; + } + + record.iter().filter(|x| **x != 0).count() == 0 + } +} +``` ## 相关题目 * 383.赎金信