diff options
Diffstat (limited to 'other/find_player_zero_one_loss.rs')
-rw-r--r-- | other/find_player_zero_one_loss.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/other/find_player_zero_one_loss.rs b/other/find_player_zero_one_loss.rs new file mode 100644 index 0000000..a0ae44e --- /dev/null +++ b/other/find_player_zero_one_loss.rs @@ -0,0 +1,14 @@ +use std::collections::BTreeMap; +struct Solution; + +impl Solution { + pub fn find_winners(matches: Vec<Vec<i32>>) -> Vec<Vec<i32>> { + let mut lost: BTreeMap<i32, i32> = matches.into_iter().fold(BTreeMap::new(), |mut hm, m| { + hm.entry(m[0]).or_insert(0); + *hm.entry(m[1]).or_insert(0) += 1; + hm + }); + return vec![lost.iter().filter(|(_, l)| **l == 0).map(|(&i, _)| i).collect(), + lost.iter().filter(|(_, l)| **l == 1).map(|(&i, _)| i).collect()]; + } +} |