MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / plus_one

Method plus_one

66. Plus One/src/main.rs:8–17  ·  view source on GitHub ↗
(mut digits: Vec<i32>)

Source from the content-addressed store, hash-verified

6
7impl Solution {
8 pub fn plus_one(mut digits: Vec<i32>) -> Vec<i32> {
9 let mut i = digits.len() - 1;
10 loop {
11 if digits[i] != 9 { digits[i] += 1; break digits }
12 /* digits[i] == 9 */
13 digits[i] = 0;
14 if i == 0 { digits.insert(0, 1); break digits }
15 i -= 1;
16 }
17 }
18}
19
20#[cfg(test)]

Callers

nothing calls this directly

Calls 1

insertMethod · 0.45

Tested by

no test coverage detected