第十周:66. Plus One
来源:互联网 发布:分期乐软件靠谱吗 编辑:程序博客网 时间:2024/06/16 11:22
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.
You may assume the integer do not contain any leading zero, except the number 0 itself.
The digits are stored such that the most significant digit is at the head of the list.
Subscribe to see which companies asked this question.
解题思路在代码里呈现:
class Solution {public: vector<int> plusOne(vector<int>& digits) { int flag = 1; //设置标志位 for(int i = digits.size() - 1; i >= 0; -- i) { int a = digits[i] + flag; digits[i] = a % 10;//当前数组值为a模10的结果 flag = a / 10;//是否有进位 } if(flag == 1) digits.insert(digits.begin(), 1);//如果最后有进位,那么在数组头插入元素1. return digits; }};
0 0
- 第十周:66. Plus One
- 66. Plus One(第六周)
- [LeetCode]66.Plus One
- LeetCode --- 66. Plus One
- [Leetcode] 66. Plus One
- [leetcode] 66.Plus One
- 66. Plus One
- 66. Plus One
- [leetcode] 66. Plus One
- Leetcode-66. Plus One
- 【leetcode】66. Plus One
- 66. Plus One
- 66. Plus One LeetCode
- 66. Plus One
- 66. Plus One
- 66. Plus One
- 66. Plus One
- 66. Plus One
- Backward Digit Sums POJ
- 生成Cordova项目,给Cordova加插件
- pwnable.kr [Toddler's Bottle]
- Ollydbg 1.10's plugin LsMem2CAry.dll
- 《ACM程序设计》书中题目K(爱搭积木的小鲍勃)
- 第十周:66. Plus One
- 基于广度优先搜索的自适应贪吃蛇实现
- 通用单链表(一)
- vivo面试笔记
- Spring AOP 项目出现 通配符的匹配很全面, 但无法找到元素 'aop:config' 的声明。错误
- Ubuntu-16.04安装Xdebug-2.2.5及相关介绍
- 103. Binary Tree Zigzag Level Order Traversal
- Codeforces 367B Sereja ans Anagrams 详细题解(map应用+维护长度)
- 《iOS10 开发指南-第一章iOS开发入门学习笔记》