Why there is runtime error in my code?


  • 0
    C

    class Solution {
    public:
    vector<int> plusOne(vector<int> &digits) {
    if(digits.size() == 0)
    return digits;
    int size = digits.size();
    int i;
    for(i = size-1; i >= 0; i--){
    if(digits[i] == 9){
    digits[i] = 0;
    }
    else
    break;
    }
    if(i == 0){
    vector<int>::iterator iter = digits.begin();
    iter = digits.insert ( iter , 1 );
    }
    else
    digits[i]++;
    return digits;
    }
    };


  • 0
    C

    Please post the code clearly if you need help.


Log in to reply
 

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