Solve contains-duplicate.
This commit is contained in:
		
							parent
							
								
									184e456e1b
								
							
						
					
					
						commit
						76ffc98ed4
					
				| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					pub fn contains_duplicate(numbers: Vec<i32>) -> bool {
 | 
				
			||||||
 | 
					  // Uncomment FromIterator in Leetcode since they're using Rust Edition 2018.
 | 
				
			||||||
 | 
					  // Edition 2021 has this trait in its prelude.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // use std::iter::FromIterator;
 | 
				
			||||||
 | 
					  std::collections::HashSet::<_>::from_iter(numbers.iter()).len()
 | 
				
			||||||
 | 
					    != numbers.len()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,5 @@
 | 
				
			||||||
pub mod add_binary;
 | 
					pub mod add_binary;
 | 
				
			||||||
 | 
					pub mod contains_duplicate;
 | 
				
			||||||
pub mod excel_sheet_column_number;
 | 
					pub mod excel_sheet_column_number;
 | 
				
			||||||
pub mod excel_sheet_column_title;
 | 
					pub mod excel_sheet_column_title;
 | 
				
			||||||
pub mod implement_strstr;
 | 
					pub mod implement_strstr;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,9 @@
 | 
				
			||||||
 | 
					use leetcode::contains_duplicate::contains_duplicate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use test_case::test_case;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[test_case(&[1, 2, 3, 1], true; "example 1")]
 | 
				
			||||||
 | 
					#[test_case(&[1, 2, 3, 4], false; "example 2")]
 | 
				
			||||||
 | 
					fn test_contains_duplicate(input: &[i32], expected: bool) {
 | 
				
			||||||
 | 
					  assert_eq!(contains_duplicate(input.to_vec()), expected);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue