Guest User

Untitled

a guest
Mar 25th, 2018
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. use std::collections::HashMap;
  2.  
  3. fn main() {
  4. // (Key, value)
  5. let list = vec![(1, 2), (3, 4), (1, 1), (3, 6), (2, 8), (1, 3)];
  6.  
  7. // Look for max value for each key in list
  8. let mut max = HashMap::new();
  9.  
  10. for &(n, x) in &list {
  11. let mut cur_max = max.entry(n).or_insert(x);
  12. if x > *cur_max {
  13. *cur_max = x;
  14. }
  15. }
  16.  
  17. println!("{:?}", max);
  18. }
Add Comment
Please, Sign In to add comment