LeetCode - 66. Plus One(0ms)
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.
The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.
You may assume the integer does not contain any leading zero, except the number 0 itself.
Example 1:
Input: [1,2,3]
Output: [1,2,4]
Explanation: The array represents the integer 123.
Example 2:
Input: [4,3,2,1]
Output: [4,3,2,2]
Explanation: The array represents the integer 4321.
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
int s = digits.size();
int flag = ;
if(digits[] == ) {
if(digits[s - ] == ) {
for(int i = ; i < s - ; i++) {
if(digits[i] == ) {
continue;
}
else {
flag = ;
break;
}
}
if(flag == ) {
vector<int> res(s + );
res[] = ;
for(int i = ; i < s; i++)
res[i] = ;
return res;
}
}
}
if(digits[s - ] == ) {
vector<int> res(s);
res[s - ] = ;
int car = ;
for(int i = s - ; i >= ; i--) {
res[i] = digits[i] + car;
if(car == ) {
if(res[i] == )
res[i] = ;
else
car = ;
}
}
return res;
}
else {
vector<int> res(digits);
res[s - ] = digits[s - ] + ;
return res;
}
}
};
LeetCode - 66. Plus One(0ms)的更多相关文章
- 前端与算法 leetcode 66. 加一
目录 # 前端与算法 leetcode 66. 加一 题目描述 概要 提示 解析 解法一 解法二 算法 # 前端与算法 leetcode 66. 加一 题目描述 给定一个由整数组成的非空数组所表示的非 ...
- LeetCode—66、88、118、119、121 Array(Easy)
66. Plus One Given a non-negative integer represented as a non-empty array of digits, plus one to th ...
- 2017-3-7 leetcode 66 119 121
今天纠结了一整天============================================================== leetcode66 https://leetcode.c ...
- leetcode 66
66. Plus One Given a non-negative number represented as an array of digits, plus one to the number. ...
- LeetCode 66. Plus One(加1)
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. Yo ...
- LeetCode(66)题解: Plus One
https://leetcode.com/problems/plus-one/ 题目: Given a non-negative number represented as an array of d ...
- [LeetCode] 66. Plus One 加一
Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The ...
- Java实现 LeetCode 66 加一
66. 加一 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示 ...
- [LeetCode]66. 加一(数组)
###题目 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 ...
随机推荐
- EJB3 调用的存储过程
要调用存储过程,我们可以通过 EntityManager 对象的 createNativeQuery()方法执行 SQL 语句 (注意:这里说的是SQL 语句,不是 EJB3 QL), 调用存储过程的 ...
- Progress
这个标签用来表示进度,常用来表示下载的进度. <progress value="22" max="100"></progress> ...
- Struts2 第二讲 -- Struts2的入门
搭建struts2环境时,我们一般需要做以下几个步骤的工作: 第一步:创建javaweb工程(这个很废话有木有) 第二步:找到开发Struts2应用需要使用到的jar文件.(这个很白痴有没有) 到ht ...
- WPF窗口模板——Style样式
通用模板,窗口样式 <!-- 通用窗口模板 --> <ControlTemplate x:Key="CustomWindowTemplate" TargetTyp ...
- js关于if(''==0)
在js当中,如下注意 if(''==0){ alert("空字符代表false"); } 空字符串代表false 0代表false false==false 结果就为true了
- layDate 闪现 循环一个以上会闪现
一个render一次渲染一个日期组件,这个是内置的,所以需要循环绑定, 又不能确定页面有多少个,还好layDate 提供了内置方法, //同时绑定多个 lay('.test-item').each(f ...
- 在Closing事件中,将e.Cancle设置成true,则Windows无法关机和重启系统的解决办法
最近在设计一个WinForm程序的时候遇到一个bug,就是From1窗体的关闭事件中设置了e.Cancle设置成true,导致系统无法关机重启,windows7 和windows xp都是这样. 我这 ...
- 企业Shell面试题及企业运维实战案例(三)
1.企业Shell面试题1:批量生成随机字符文件名案例 使用for循环在/oldboy目录下批量创建10个html文件,其中每个文件需要包含10个随机小写字母加固定字符串oldboy,名称示例如下: ...
- 【坑】记录一个docker 1.13.1 build 07f3374 版本的坑
在自家的开发环境中,一般都是直接yum安装最新的docker来做镜像和容器,没有仔细深究,一直相安无事.但这几天却发现一个惊悚的现象,新申请的两台虚机,一台安装好后正常,另一台却出现异常: docke ...
- 接口API封装中常见的HTTP状态码
在进行后端接口API封装的过程中,需要考虑各种错误信息的输出.一般情况下,根据相应问题输出适合的HTTP状态码,可以方便前端快速定位错误,减少沟通成本. HTTP状态码有很多,每个都有对应的含义,下面 ...