1
Fork 0

Make changes suggested by Clippy.

This commit is contained in:
Bauke 2022-04-08 23:00:38 +02:00
parent 15ac4ec45c
commit ea43830954
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
5 changed files with 8 additions and 10 deletions

View File

@ -9,9 +9,8 @@ pub fn add_binary(a: String, b: String) -> String {
let mut sum = String::new();
// Create reversed iterators for both binary strings.
let (mut a, mut b) = (a.chars().rev(), b.chars().rev());
while let Some(a) = a.next() {
let mut b = b.chars().rev();
for a in a.chars().rev() {
// Safe to unwrap since we know both iterators will be the same length.
let b = b.next().unwrap();

View File

@ -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.
let mut strings = strings.clone();
strings.sort_by(|a, b| a.len().cmp(&b.len()));
strings.sort_by_key(|a| a.len());
// Then grab the shortest string.
let shortest_string = match strings.first() {

View File

@ -8,7 +8,7 @@ pub fn plus_one(digits: Vec<i32>) -> Vec<i32> {
// Create a vector to store the incremented digits.
let mut incremented = vec![];
while let Some(digit) = digits.next() {
for digit in digits.by_ref() {
if digit == 9 {
// When the current digit is 9 save 0 and keep going through the digits.
incremented.push(0);

View File

@ -6,10 +6,10 @@ pub fn is_anagram(a: String, b: String) -> bool {
// Sort both strings' characters so they're in alphabetical order.
let mut a = a.chars().collect::<Vec<_>>();
a.sort();
a.sort_unstable();
let mut b = b.chars().collect::<Vec<_>>();
b.sort();
b.sort_unstable();
// And if they are equal, then they're anagrams.
a == b

View File

@ -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
// string is invalid.
stack.len() == 0
stack.is_empty()
}