use std::collections::HashMap; use std::collections::HashSet;
fnsearch_m<'a>(hashmap: HashMap<&str, Vec<&'astr>>) -> Option<&'astr> { letmut queue: Vec<&str> = Vec::new(); letmut check_list = HashSet::new(); ifletSome(first) = hashmap.get("you") { for ele in first { queue.push(ele); } } while queue.len() > 0 { let c = queue.remove(0); if check_list.contains(c) { continue; } check_list.insert(c); if c.ends_with("m") { returnSome(c); } ifletSome(eles) = hashmap.get(c) { for ele in eles { queue.push(ele) } } } None }
/** * 找出元素中的最大值 */ functionmaxNumber(arr: number[]) { if (arr.length === 0) { return -Infinity; } let [i, ...rest] = arr; let max = maxNumber(rest); return i > max ? i : max; }
fnselection_sort(arr: Vec<i32>) -> Vec<i32> { letmut min = std::i32::MIN; letmut result = vec![]; for _i in &arr { let c_min = find_small(&arr, min); min = c_min; result.push(c_min); } result } fnfind_small(arr: &Vec<i32>, min: i32) -> i32 { letmut c_min = std::i32::MAX; for i in arr { if *i <= min { continue; } if *i < c_min { c_min = *i; } } c_min }
/** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. */ impl MinStack { /** initialize your data structure here. */ fnnew() -> Self { return MinStack { stack_a: vec![], stack_b: vec![], }; }