forked from namishkhanna/hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlus_One.cpp
More file actions
32 lines (28 loc) · 651 Bytes
/
Copy pathPlus_One.cpp
File metadata and controls
32 lines (28 loc) · 651 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//computerwala
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
if(digits == null || digits.size() == 0){
int[] temp = {1};
return temp;
}
int carry = 1;
int i;
for(i=digits.size()-1; i>0;i--) {
if(digits[i]=9){
digits[i]=0;
}
else{
carry+ = digits[i];
digits[i] = carry;
break;
}
if(i<0){
int[] result = new int[digits.size()+1];
result[0] = 1;
return result;
} else{
return digits;
}
}
};