Skip to content

Commit 90ce01d

Browse files
authoredJan 3, 2023
Fix 0242-valid-anagram.rs
Line #13 would cause an underflow on latest rustc 1.66.0, but not on leetcode. Changed to signed integer type to prevent underflow. Submission URL: https://leetcode.com/problems/valid-anagram/submissions/870368270/
1 parent af34357 commit 90ce01d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎rust/0242-valid-anagram.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ impl Solution {
66
return false;
77
}
88

9-
let mut map: HashMap<char, usize> = HashMap::new();
9+
let mut map: HashMap<char, i64> = HashMap::new();
1010

1111
for (a, b) in s.chars().zip(t.chars()){
12-
*map.entry(a).or_default() +=1;
13-
*map.entry(b).or_default() -=1;
12+
*map.entry(a).or_default() += 1;
13+
*map.entry(b).or_default() -= 1;
1414
}
1515

1616
map.into_values().all(|cnt| cnt == 0)
1717
}
18-
}
18+
}

0 commit comments

Comments
 (0)
Please sign in to comment.