Leetcode 66: https://leetcode.com/problems/plus-one/ class Solution {… — C Programming Language || Hands On Coding — TG.ME

Leetcode 66:
https://leetcode.com/problems/plus-one/
class Solution {
public:
std::vector<int> plusOne(std::vector<int>& digits) {
int currentIndex = digits.size() - 1;

while (digits[currentIndex] == 9) {
if (currentIndex == 0) {
std::vector<int> resultArr(digits.size() + 1, 0);
resultArr[0] = 1;
return resultArr;
}
digits[currentIndex] = 0;
currentIndex--;
}

digits[currentIndex]++;
return digits;
}
};
👍8❤3🥰1😁1
March 20, 2025 16.9K 21