首页 > 代码库 > LeetCode Plus One

LeetCode Plus One

class Solution {public:    vector<int> plusOne(vector<int> &digits) {        int carry = 1;        int len = digits.size();                vector<int> res;                for (int i=len-1; i>=0; i--) {            int cur = carry + digits[i];            carry = cur / 10;            cur = cur % 10;            res.push_back(cur);        }        if (carry) {            res.push_back(1);        }        reverse(res.begin(), res.end());        return res;    }};

水一发