Got the wrong answer in here!!


  • 0
    R
    class Solution {
    public:
        vector<int> plusOne(vector<int> &digits) {
        	vector<int>::iterator itr=digits.begin();
        	long num=0;
        	for(;itr!=digits.end();itr++){
        		num*=10;
        		num=num+(*itr);
        	}
        	num+=1;
        
        	vector<int> out;
        	vector<int>::iterator itr1=out.begin();
        	while(num!=0){
        		int mod=num%10;
        		itr1=out.insert(out.begin(),mod);
        		num/=10;
        	}
    
        	return out;        
        }
    };
    

    Input: [9,8,7,6,5,4,3,2,1,0]
    Output: [1,2,8,6,6,0,8,6,1,9]
    Expected: [9,8,7,6,5,4,3,2,1,1]

    I don't know why it got [1,2,8,6,6,0,8,6,1,9] in here???
    I tested this code on my machine, it is [9,8,7,6,5,4,3,2,1,1].

    Help please!


Log in to reply
 

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