My LeetCode grinding. Trying to do a problem a day.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

main.rs 451B

123456789101112131415161718
  1. use std::collections::HashMap;
  2. pub fn repeated_n_times(a: Vec<i32>) -> i32 {
  3. let mut hm = HashMap::new();
  4. for i in a {
  5. if hm.contains_key(&i) {
  6. return i;
  7. } else {
  8. hm.insert(i, 0);
  9. }
  10. }
  11. return 0; // This is unecessary given the problem constraints, but rust needs it to be happy
  12. }
  13. pub fn main() {
  14. println!("Expected: 3");
  15. println!("Got: {}", repeated_n_times(vec![1 ,2, 3, 3]))
  16. }