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

Function half_questions

lcs-WqXACV.rs:1–16  ·  view source on GitHub ↗
(questions: Vec<i32>)

Source from the content-addressed store, hash-verified

1pub fn half_questions(questions: Vec<i32>) -> i32 {
2 let n = questions.len() / 2;
3 use std::collections::HashMap;
4 let mut mmp = HashMap::new();
5 for i in questions { *mmp.entry(i).or_insert(0) += 1 }
6 let mut mmp_vec: Vec<_> = mmp.iter().collect();
7 mmp_vec.sort_by(|b, a|a.1.cmp(&b.1));
8 let mut ret = 0;
9 let mut current = 0;
10 for e in mmp_vec {
11 ret += 1;
12 current += e.1;
13 if current >= n { break }
14 }
15 ret
16}
17
18fn main() {
19 println!("{:?}", half_questions(vec![13,8,3,7,5,6,11,12,3,6,6,11]));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected