feat: 771_jewels_and_stones

This commit is contained in:
SquidSpirit 2025-08-20 01:53:00 +08:00
parent eb5e426fdb
commit 5428c96ba7
3 changed files with 31 additions and 0 deletions

7
771_jewels_and_stones/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "jewels_and_stones"
version = "0.1.0"

View File

@ -0,0 +1,6 @@
[package]
name = "jewels_and_stones"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@ -0,0 +1,18 @@
use std::collections::HashSet;
pub struct Solution;
impl Solution {
pub fn num_jewels_in_stones(jewels: String, stones: String) -> i32 {
let jewels: HashSet<char> = HashSet::from_iter(jewels.chars());
let mut result = 0;
for stone in stones.chars() {
if jewels.contains(&stone) {
result += 1;
}
}
result
}
}