C++ easy understand


  • 1
    B
    vector<int> plusOne(vector<int>& digits) {
        vector<int> plusOne;
        int len = digits.size();
        int num = 1;
        int temp = 0;
        for(int i = len-1;i>=0;i--)
        {
            temp = (digits[i] + num)%10;
            num = (digits[i] + num)/10;
            plusOne.push_back(temp);
        }
        if(num != 0)
        {
            plusOne.push_back(num);
        }
        reverse(plusOne.begin(),plusOne.end());
        return plusOne;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.