My C++ solution


  • 0
    V

    class Solution {
    public:
    vector<int> plusOne(vector<int> &digits) {

       int n=digits.size();
       
       int p=n-1;
       while(p){
           if(digits[p]<9){digits[p]++;return digits;}
           else{digits[p]=0;p--;}
       }
       if(digits[0]<9){digits[0]++;return digits;}
       else{
           digits[0]=1;
          digits.push_back(0);
          return digits;
       }
    }
    

    };


Log in to reply
 

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