My C++ 4ms Solution


  • -1
    L
    vector<int> plusOne(vector<int>& digits) {
       int i = digits.size() -1;
       digits[i] += 1;
    
       while(i>=0){ 
       		if(i==0){
       			if(digits[i]==10){
       				digits[i]=1;
       				digits.push_back(0);
       			}
       			return digits;
       		}else{
    			if(digits[i] == 10){
       			digits[i]=0;
       			digits[i-1] +=1;
       			}
    		}
       		i--;
    	}   
            
    }

Log in to reply
 

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