20240730 Finished

This commit is contained in:
jackfiled 2024-07-30 13:51:40 +08:00
parent 17ee25130e
commit bd6382ab87
2 changed files with 40 additions and 1 deletions

View File

@ -188,4 +188,5 @@ mod p190_reverse_bits;
mod p191_number_of_1_bits;
mod p136_single_number;
mod p137_single_number_ii;
mod p201_bitwise_and_of_numbers_range;
mod p201_bitwise_and_of_numbers_range;
mod p66_plus_one;

View File

@ -0,0 +1,38 @@
/**
* [66] Plus One
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn plus_one(digits: Vec<i32>) -> Vec<i32> {
let mut digits = digits;
let mut overflow = 1;
for i in (0..digits.len()).rev() {
let bit = digits[i] + overflow;
digits[i] = bit % 10;
overflow = bit / 10;
}
if overflow > 0 {
digits.insert(0, overflow);
}
digits
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_66() {
assert_eq!(vec![1, 0], Solution::plus_one(vec![9]));
}
}