LeetCode 1079. Letter Tile Possibilities

Problem Statement


use std::collections::HashSet;
impl Solution {
fn dfs(set: &mut HashSet<String>, level: usize, tiles: &String,
cur: &mut String, used: &mut Vec<bool>) {
let size = tiles.len();
if size == level {
return;
}
for i in 0..size {
if used[i] {
continue;
}
used[i] = true;
let char = tiles.chars().nth(i).unwrap();
cur.push(char);
set.insert(cur.clone());
Self::dfs(set, level + 1, tiles, cur, used);
used[i] = false;
cur.pop();
}
}
pub fn num_tile_possibilities(tiles: String) -> i32 {
let (mut set, input, mut cur, mut used) =
(HashSet::new(), tiles.clone(), "".to_string(), vec![false; tiles.len()]);
Self::dfs(&mut set, 0, &input, &mut cur, &mut used);
return set.len() as i32;
}
}