MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / new

Method new

398-random-pick-index.rs:9–17  ·  view source on GitHub ↗
(nums: Vec<i32>)

Source from the content-addressed store, hash-verified

7impl Solution {
8
9 fn new(nums: Vec<i32>) -> Self {
10 let mut mmp = HashMap::new();
11 for (i, num) in nums.iter().enumerate() {
12 mmp.entry(*num).or_insert(Vec::new()).push(i);
13 }
14 Solution {
15 mmp: mmp
16 }
17 }
18
19 fn pick(&mut self, target: i32) -> i32 {
20 self.mmp.get_mut(&target).unwrap().rotate_right(1);

Callers

nothing calls this directly

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected