17:Plus One
来源:互联网 发布:江歌案始末知乎 编辑:程序博客网 时间:2024/06/13 09:13
注:本题的解法思想及参考的代码来自于https://github.com/soulmachine/leetcode#leetcode题解
题目:Given a number represented as an array of digits, plus one to the number
代码如下:
//时间复杂度O(n),空间复杂度O(1)class Solution {public: vector<int> plusOne(vector<int>& digits) { add(digits, 1); return digits; }private: // 0 <= digit <=9 void add(vector<int>& digits, int digit) { int c = digit; for (int i = digits.size() - 1; i >= 0; --i) { digits[i] += c; c = digits[i] / 10; digits[i] %= 10; } /* for (auto it = digits.rbegin(); it != digits.rend(); ++it) { *it += c; c = *it / 10; *it %= 10; } */ if (c != 0) digits.insert(digits.begin(), c); }};
0 0
- 2.1.17 Plus One
- 17:Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- 16: Rotate Image
- 类的构造函数
- IOS的app运行时上下有黑边,非全屏
- 从 php 内核挂载钩子解密源码
- 二维有序数组的查找 python解决
- 17:Plus One
- [201702w3]如何变得会聊天
- 11g 如何添加,替换,移除,迁移 OCR ?
- 利用Python搭建的简易排序搜索引擎
- python安装requests库
- 初识Hadoop
- Android 生命周期详解【附demo源码】
- ISSCC 2017论文导读 Session 14:ENVISION: A 0.26-to-10 TOPS/W Subword-Parallel DVAFS CNN Processor in 28nm
- C++ Primer 第5版--练习9.43 & 9.44