Wrong Answer for the test case


  • 0
    G
       vector<int> plusOne(vector<int> &digits) {
            int sum,carry=0;
            int i;
            int lastdig;vector<int> result;
            vector<int>::iterator it;
            if(digits.size()==0){
                result.push_back(1);
                return result;
            }
      it = digits.begin();
            int n=((digits.size())-1);
            //cout<<digits[n];
            for(i=0;i<=n;i++)
            {   sum=0;
            	if(i==0){
                sum=(digits.at(n-i)+1)+carry;
           }
            else
            {
            	sum=(digits.at(n-i))+carry;
            }
               cout<<sum<<endl;
               if(sum>=10){
                carry=sum/10;
                sum=sum-10;
              }
                else{
                    carry=0;
                }
                digits.at(n-i)=sum;
                lastdig=carry;            
            }
            if(lastdig){        	
            	it=digits.insert(it,lastdig);
            }
            result=digits;        
            return result; 
        }
    };
    

    As far as I know i'm returning a vector,but it's showing an error as Input:[0]
    Output: 1
    Expected: [1]


Log in to reply
 

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