【leetcode】plus One

问题描述:

Given a non-negative number represented as an array of digits, plus one to the number.

The digits are stored such that the most significant digit is at the head of the list.

很简单就是像写大数加法那样,代码如下

 class Solution {
public:
vector<int> plusOne(vector<int> &digits) {
int l=digits.size();
if(l==){
return digits;
}
if(l==){
if(digits[]!=){
digits[]++;
return digits;
}
else{
vector<int> v;
v.push_back();
v.push_back();
return v;
}
}
int flg=;
int temp=digits[l-]+;
if(temp>){
digits[l-]=;
flg=;
}
else{
digits[l-]=temp;
return digits;
}
for(int i=l-;i>=;i--){
int temp=digits[i]+;
if(temp>){
digits[i]=;
flg=;
}
else{
digits[i]=temp;
return digits;
}
}
if(flg){
//vector<int>::iterator it=;
digits.insert(digits.begin(),);
}
return digits;
}
};
上一篇:android隐藏底部虚拟键Navigation Bar实现全屏


下一篇:[React Fundamentals] Owner Ownee Relationship