zoukankan      html  css  js  c++  java
  • [LeetCode] Plus One

    Given a number represented as an array of digits, plus one to the number.

    class Solution {
    public:
        vector<int> plusOne(vector<int> &digits) {
            // IMPORTANT: Please reset any member data you declared, as
            // the same Solution instance will be reused for each test case.
            int a = 1;
            vector<int> ans;
            vector<int>::iterator it;
            for(int i = digits.size() - 1;i >= 0;i--)
            {
                it = ans.begin();
                int b = (a + digits[i]) % 10;
                a = (a + digits[i]) / 10;
                ans.insert(it, b);
            }
            if(a != 0)
            {
                it = ans.begin();
                ans.insert(it, a);
            }
            
            return ans;
        }
    };
  • 相关阅读:
    van Emda Boas
    斐波那契堆
    NTT
    FFT
    KDTree
    扩展kmp
    kmp
    Dancing Links
    树的prufer编码
    有向图最小路径覆盖
  • 原文地址:https://www.cnblogs.com/changchengxiao/p/3419269.html
Copyright © 2011-2022 走看看