-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path66.cpp
More file actions
35 lines (31 loc) · 721 Bytes
/
66.cpp
File metadata and controls
35 lines (31 loc) · 721 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
33
34
35
// Problem : 66. Plus One
// Link : https://leetcode.com/problems/plus-one/
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
for(int i = digits.size() - 1; i >= 0; i--){
if(digits[i] == 9)
digits[i] = 0;
else{
++digits[i];
return digits;
}
}
digits.push_back(0);
digits[0] = 1;
return digits;
}
};
int main() {
Solution ob;
vector<int> digits{9,9,9,9};
vector<int> solution = ob.plusOne(digits);
for(int i : solution){
cout << i << ",";
}
return 0;
}