From baf7ed122b1cb78b89565b83b343a4f3c5f5ec82 Mon Sep 17 00:00:00 2001 From: "junjie2.luo" Date: Thu, 10 Oct 2024 17:18:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=201207.=E7=8B=AC=E4=B8=80=E6=97=A0?= =?UTF-8?q?=E4=BA=8C=E7=9A=84=E5=87=BA=E7=8E=B0=E6=AC=A1=E6=95=B0,?= =?UTF-8?q?=E6=96=B0=E5=A2=9Erust=E8=A7=A3=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/1207.独一无二的出现次数.md | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/problems/1207.独一无二的出现次数.md b/problems/1207.独一无二的出现次数.md index cd89522e..781badf5 100644 --- a/problems/1207.独一无二的出现次数.md +++ b/problems/1207.独一无二的出现次数.md @@ -221,6 +221,28 @@ func uniqueOccurrences(arr []int) bool { } ``` +### Rust + +```rust +use std::collections::{HashMap, HashSet}; +impl Solution { + pub fn unique_occurrences(arr: Vec) -> bool { + let mut hash = HashMap::::new(); + for x in arr { + *hash.entry(x).or_insert(0) += 1; + } + let mut set = HashSet::::new(); + for (_k, v) in hash { + if set.contains(&v) { + return false + } else { + set.insert(v); + } + } + true + } +} +```