알고리즘_개념 및 문제풀이
leetcode/plusone
swdream
2019. 10. 5. 14:19
반응형
https://leetcode.com/problems/plus-one
Plus One - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
vector<int> plusOne(vector<int>& digits) {
vector<int> answer;
for(int i = digits.size()-1; i >= 0; i--){
if(digits[i] < 9){
digits[i] = digits[i] + 1;
break;
}
else{
if(i == 0){
digits[i]=1;
digits.push_back(0);
}
else{
digits[i]=0;
}
}
}
answer = digits;
return answer;
}
반응형