【leetcode】66-PlusOne
problem
code
- class Solution {
- public:
- vector<int> plusOne(vector<int>& digits) {
- vector<int> res;
- int carry = ;
- int sum = ;
- int mod = ;
- int i = digits.size()-;
- while(carry && i>=)
- {
- sum = digits[i] + carry;
- carry = sum / ;
- mod = sum % ;
- res.push_back(mod);
- i--;
- }
- if(carry && i<) res.push_back(carry);
- for( ; i>=; i--)
- {
- res.push_back(digits[i]);
- }
- reverse(res.begin(), res.end());
- return res;
- }
- };
注意可能有进位,而且可能有多个进位,另外注意最高位有进位的情况。
参考
1.leetcode;
完
【leetcode】66-PlusOne的更多相关文章
- 【LeetCode】66. Plus One 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数九 采用进位 日期 [LeetCode] 题目地址 ...
- 【LeetCode】66 & 67- Plus One & Add Binary
66 - Plus One Given a non-negative number represented as an array of digits, plus one to the number. ...
- 【LeetCode】66. 加一
66. 加一 知识点:数组: 题目描述 给定一个由 整数 组成的 非空 数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 ...
- 【LeetCode】66. Plus One
题目: Given a non-negative number represented as an array of digits, plus one to the number. The digit ...
- 【LeetCode】66. Plus One (2 solutions)
Plus One Given a non-negative number represented as an array of digits, plus one to the number. The ...
- 【LEETCODE】66、字符串分类,hard级别,题目:32,72,76
package y2019.Algorithm.str.hard; import java.util.Stack; /** * @ProjectName: cutter-point * @Packag ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【Leetcode】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
- 27. Remove Element【leetcode】
27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...
随机推荐
- SQL SERVER版本补丁体系及升级
首先了解几个定义: RTM : 表示 Release to Manufacturing ,这是产品的原始发布版本,当从光盘或 MSDN 下载的默认版本.不过现在下载 SQL Server 版本时,也有 ...
- sublime ctags跳转函数使用
sublime 点击某函数 按F12可以查到相关函数文件 正题: 1.下载ctags客户端文件 http://prdownloads.sourceforge.net/ctags/ctags58.zip ...
- fiddler 抓包配置
1.我们安装完成后点击运行程序,就可以看到如下图,这是进入Fildder的第一个界面. 2.安装好后打开fiddler→选择 Tools >Fildder Options > Https ...
- 人机交互之QQ拼音
随着电脑系统的不断更新,电脑自带的系统输入法也越来越适应广大群众了,那为什么其他的输入法还能占有大量的用户呢? 首先系统输入法是面向大众的,个性化方面略显不足. 其次系统输入法功能不够全面,比如说手写 ...
- AdminLTE 文档
一个基于 bootstrap 的轻量级后台模板,这个前端界面个人感觉很清爽,对于一个大后端的我来说,可以减少较多的时间去承担前端的工作但又必须去独立去完成一个后台系统开发的任务,并且,文档还算比较齐全 ...
- VS 中常用的一些快捷键
一.代码自动对齐 CTRL+K+F 二.撤销/反撤销 1.撤销---使用组合键“Ctrl+Z”进行撤销操作 2.反撤销---使用组合键“Ctrl+Y”进行反撤销操作 三.调用智能提示 使用组合 ...
- 【原创】<Debug> QT头文件
[Error] No such file or directory [Solution] 参考: http://blog.csdn.net/donglynn/article/details/21804 ...
- HTTP协议详细解析
HTTP协议详解 HTTP协议(HyperText Transfer Protocol,超文本传输协议)是因特网上应用最为广泛的一种网络传输协议,所有的WWW文件都必须遵守这个标准. HTTP是一个基 ...
- Android : 网络adb配置及有线端口占用解决方法
一.调试环境: Android Debug Bridge version 1.0.40: Nexus6P平板(Android 8.0系统): 二.网络ADB调试: 1. Android设备除了用有线u ...
- transclude
http://jsfiddle.net/ospatil/A969Z/157/ transclude :true 允许指令内部的dom元素, 保留到 自定义指令的template属性里的含有 ng-t ...