Make changes suggested by Clippy.
This commit is contained in:
		
							parent
							
								
									15ac4ec45c
								
							
						
					
					
						commit
						ea43830954
					
				|  | @ -9,9 +9,8 @@ pub fn add_binary(a: String, b: String) -> String { | ||||||
|   let mut sum = String::new(); |   let mut sum = String::new(); | ||||||
| 
 | 
 | ||||||
|   // Create reversed iterators for both binary strings.
 |   // Create reversed iterators for both binary strings.
 | ||||||
|   let (mut a, mut b) = (a.chars().rev(), b.chars().rev()); |   let mut b = b.chars().rev(); | ||||||
| 
 |   for a in a.chars().rev() { | ||||||
|   while let Some(a) = a.next() { |  | ||||||
|     // Safe to unwrap since we know both iterators will be the same length.
 |     // Safe to unwrap since we know both iterators will be the same length.
 | ||||||
|     let b = b.next().unwrap(); |     let b = b.next().unwrap(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| pub fn longest_common_prefix(strings: Vec<String>) -> String { | pub fn longest_common_prefix(mut strings: Vec<String>) -> String { | ||||||
|   // Sort the strings ascending by length.
 |   // Sort the strings ascending by length.
 | ||||||
|   let mut strings = strings.clone(); |   strings.sort_by_key(|a| a.len()); | ||||||
|   strings.sort_by(|a, b| a.len().cmp(&b.len())); |  | ||||||
| 
 | 
 | ||||||
|   // Then grab the shortest string.
 |   // Then grab the shortest string.
 | ||||||
|   let shortest_string = match strings.first() { |   let shortest_string = match strings.first() { | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ pub fn plus_one(digits: Vec<i32>) -> Vec<i32> { | ||||||
|   // Create a vector to store the incremented digits.
 |   // Create a vector to store the incremented digits.
 | ||||||
|   let mut incremented = vec![]; |   let mut incremented = vec![]; | ||||||
| 
 | 
 | ||||||
|   while let Some(digit) = digits.next() { |   for digit in digits.by_ref() { | ||||||
|     if digit == 9 { |     if digit == 9 { | ||||||
|       // When the current digit is 9 save 0 and keep going through the digits.
 |       // When the current digit is 9 save 0 and keep going through the digits.
 | ||||||
|       incremented.push(0); |       incremented.push(0); | ||||||
|  |  | ||||||
|  | @ -6,10 +6,10 @@ pub fn is_anagram(a: String, b: String) -> bool { | ||||||
| 
 | 
 | ||||||
|   // Sort both strings' characters so they're in alphabetical order.
 |   // Sort both strings' characters so they're in alphabetical order.
 | ||||||
|   let mut a = a.chars().collect::<Vec<_>>(); |   let mut a = a.chars().collect::<Vec<_>>(); | ||||||
|   a.sort(); |   a.sort_unstable(); | ||||||
| 
 | 
 | ||||||
|   let mut b = b.chars().collect::<Vec<_>>(); |   let mut b = b.chars().collect::<Vec<_>>(); | ||||||
|   b.sort(); |   b.sort_unstable(); | ||||||
| 
 | 
 | ||||||
|   // And if they are equal, then they're anagrams.
 |   // And if they are equal, then they're anagrams.
 | ||||||
|   a == b |   a == b | ||||||
|  |  | ||||||
|  | @ -35,5 +35,5 @@ pub fn is_valid(string: String) -> bool { | ||||||
| 
 | 
 | ||||||
|   // After the string has been looped over, if anything is left in the stack the
 |   // After the string has been looped over, if anything is left in the stack the
 | ||||||
|   // string is invalid.
 |   // string is invalid.
 | ||||||
|   stack.len() == 0 |   stack.is_empty() | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue