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 之外,这个整数不会以零开头. 示例 ...
随机推荐
- Android 滑动效果汇总
Android 滑动效果入门篇(一)—— ViewFlipper Android 滑动效果入门篇(二)—— Gallery Android 滑动效果基础篇(三)—— Gallery仿图像集浏览 And ...
- opencv 数据类型转换:CvArr, Mat, CvMat, IplImage, BYTE 转
留着以后查询: http://blog.csdn.net/augusdi/article/details/8863820 一.Mat类型:矩阵类型,Matrix. 在openCV中,Mat是一个多维的 ...
- 关闭Debut.Log
unity5.3支持了运行时关闭产生的debug.log Debug.logger.logEnabled = false; 谢谢你们,让我能在晚上凝视夜空的时候,脑海中浮现出更广阔的世界.
- JavaScript自己整理的基础-01
1.JavaScript 简介: JavaScript是互联网上最流行的脚本语言,所有现代的HTML都使用JavaScript.既然是脚本语言,那么它的特点就有一下三种: (1)弱类型: (2)解释型 ...
- SpringBoot非官方教程 | 第十三篇:springboot集成spring cache
转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot13-springcache/ 本文出自方志朋的博 ...
- Linux修改时区以及同步时间
Centos7为例:修改时区 timedatectl list-timezones |grep Shanghai #查找中国时区的完整名称 Asia/Shanghai timedatectl set- ...
- Invalid default value for prop "value": Props with type Object/Array must use a factory function to return the default value.(props default 数组/对象的默认值应当由一个工厂函数返回)
Invalid default value for prop "value": Props with type Object/Array must use a factory fu ...
- jdbc学习笔记02
数据库连接池 DBCP DataBase Conection Pool:数据库连接池 如果没有数据库连接池,每一次业务都需要服务器和数据库服务器建立一次连接,业务处理完连接断开,如果有1万次业务处理, ...
- hibernate笔记1
1. 数据库中的表关系 一对一.一对多(多对一).多对一 2. 如何确立表中的表关系 一对多的关系如何实现:使用外键约束,一的方称为主表,多的方称为从表. 外键:从表中有一列,该列的取值除了nul ...
- JavaSE 第二次学习随笔(五)
/* * 中文乱码出现的情况研究 * 注意点:乱码解决的办法是再编码再解码 * 但是如果是编码出错了,无法解决.如果是解码出错了,可以利用再编码再解码 * * * 编码 解码 结果 * GBK utf ...