Leetcode 66 plus one Tree Solution in c++ | Hindi Coding Community

0

 

You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's.

Increment the large integer by one and return the resulting array of digits.


class Solution {
public:
vector<int> plusOne(vector<int>& d) {
for(int i=d.size()-1;i>=0;i--) {
if(d[i]<9){
d[i]++;
return d;
}
else{
d[i]=0;
}
}
d.push_back(0);
d[0]=1;

return d;
}
};

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !