We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9da3853 commit 6c292cdCopy full SHA for 6c292cd
exercises/02_basic_calculator/09_saturating/src/lib.rs
@@ -1,9 +1,9 @@
1
pub fn factorial(n: u32) -> u32 {
2
- let mut result = 1;
+ let mut result: u32 = 1;
3
for i in 1..=n {
4
// Use saturating multiplication to stop at the maximum value of u32
5
// rather than overflowing and wrapping around
6
- result *= i;
+ result = result.saturating_mul(i);
7
}
8
result
9
0 commit comments