66. add one-tenth
Title Description : Given a non negative integer represented by a non empty array of integers , Add one to the number .

The highest digit is stored at the top of the array , Each element in the array stores only a single number .

You can assume that except for integers 0 outside , This integer does not start with zero .

Thinking of problem solving :
To divide 3 In this paper, we discuss the situation :
1. When input The last digit of is less than 9 The situation , Just add one at the end ;
2. A case involving a carry, for example [1,9]+[1], Let the last place be 0, The second highest position needs to enter one ;
3. When multiple carry is involved , such as [9,9]+[1], The size of the array will increase , There is one more place in the highest position .
class Solution { public: vector<int> plusOne(vector<int>& digits) { int len =
digits.size(); // Loop from last bit array for(int i = len - 1; i >= 0; --i){ // If a certain number of digits <9, In this position +1 that will do
if(digits[i] < 9){ ++digits[i]; return digits; } if(i == 0){
// When cycling to the highest position , Highest order assignment 1, And add in the last digit of the number 0( For similar [9,9,9] Such an array ) digits[i] = 1;
//push_back Is to insert elements into an array digits.push_back(0); } else
// It hasn't been cycled to the highest bit and digits[i]=9 Time , This bit is assigned as 0 digits[i] = 0; } return digits; } };

Technology
©2019-2020 Toolsou All rights reserved,
ELementUI select Multi select drop-down box to get all properties of the selected item mysql Modify primary key Element-UI Implementation of secondary packaging TreeSelect Tree drop-down selection component Cheats developers apologize ( Essence )2020 year 7 month 12 day webpack Use of common plug-ins ( Essence )2020 year 6 month 26 day C# Class library read json Profile help class fio Use details Front end to background 5 Summary of different ways PostgreSQL: Nine . Indexes JQ get request Splicing url parameter ( query criteria )