LeetCode(66)题解: Plus One
https://leetcode.com/problems/plus-one/
题目:
Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.
思路:
设置进1位,逢9进1。注意999这种情况要首位insert1。
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
int n=digits.size();
bool jinyi=false;
for(int i=n-;i>=;i--){
if(digits[i]==){
digits[i]=;
jinyi=true;
}
else{
digits[i]++;
jinyi=false;
break;
}
}
if(jinyi==true){
vector <int>::iterator theIterator = digits.begin();
digits.insert(theIterator,,);
}
return digits;
}
};
LeetCode(66)题解: Plus One的更多相关文章
- LeetCode OJ 题解
博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...
- Leetcode 简略题解 - 共567题
Leetcode 简略题解 - 共567题 写在开头:我作为一个老实人,一向非常反感骗赞.收智商税两种行为.前几天看到不止两三位用户说自己辛苦写了干货,结果收藏数是点赞数的三倍有余,感觉自己的 ...
- 前端与算法 leetcode 66. 加一
目录 # 前端与算法 leetcode 66. 加一 题目描述 概要 提示 解析 解法一 解法二 算法 # 前端与算法 leetcode 66. 加一 题目描述 给定一个由整数组成的非空数组所表示的非 ...
- CFEducational Codeforces Round 66题解报告
CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...
- LeetCode 算法题解 js 版 (001 Two Sum)
LeetCode 算法题解 js 版 (001 Two Sum) 两数之和 https://leetcode.com/problems/two-sum/submissions/ https://lee ...
- leetcode & lintcode 题解
刷题备忘录,for bug-free 招行面试题--求无序数组最长连续序列的长度,这里连续指的是值连续--间隔为1,并不是数值的位置连续 问题: 给出一个未排序的整数数组,找出最长的连续元素序列的长度 ...
- 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 ...
- LeetCode一句话题解
深度优先搜索 人生经验 1. 需要输出所有解.并由于元素集有重复元素,要求返回的结果需要去重的情况,可考虑使用值对应数量的map,然后分别考虑依次取不同数量该值的可能. LeetCode39 题目:给 ...
- 2017-3-7 leetcode 66 119 121
今天纠结了一整天============================================================== leetcode66 https://leetcode.c ...
随机推荐
- 图论trainning-part-2 B. Claw Decomposition
B. Claw Decomposition Time Limit: 1000ms Memory Limit: 131072KB 64-bit integer IO format: %lld ...
- Linux中执行shell脚本命令的4种方法总结
bash shell 脚本的方法有多种,现在作个小结.假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限. 方法一:切换到shell脚本所在 ...
- 九度oj 题目1102:最小面积子矩阵
题目描述: 一个N*M的矩阵,找出这个矩阵中所有元素的和不小于K的面积最小的子矩阵(矩阵中元素个数为矩阵面积) 输入: 每个案例第一行三个正整数N,M<=100,表示矩阵大小,和一个整数K接下来 ...
- tomcat的安装和优化二
JAVA应用服务器weblogicwebsphere tomcat resin(百度,去哪网,搜狗,人人,互动百科)jboss resin官网:www.caucho.com jvm的调优: 1 JAM ...
- nginx报错 too many open files in system
系统进不去了,用ssh连接服务器也非常慢,负载均衡显示后端连接异常,重启mysql数据库,发现经常重启,或者直接关机,访问页面也访问不到. http://www.51testing.com/html/ ...
- php.ini配置参数详解
下面对php.ini中一些安全相关参数的配置进行说明 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2 ...
- iOS学习笔记17-FMDB
上一节我已经介绍了SQLite的简单使用,不了解的可以提前去看一下iOS学习笔记16-数据库SQLite,这节我们来讲下FMDB. 一.FMDB介绍 FMDB是一种第三方的开源库,FMDB就是对SQL ...
- BZOJ 2829 信用卡凸包 ——计算几何
凸包裸题 #include <map> #include <cmath> #include <queue> #include <cstdio> #inc ...
- SPOJ CIRU The area of the union of circles ——Simpson积分
[题目分析] 圆的面积并. 直接Simpson积分,(但是有计算几何的解法,留着flag). simpson积分,如果圆出现了不连续的情况,是很容易出事情的.(脑补一下) 但是没有什么办法,本来就是一 ...
- SQL Server中的@@ROWCOUNT
SQL Server中@@ROWCOUNT返回受上一语句影响的行数,返回值类型为 int 整型. 如果行数大于 20 亿,则需要使用 ROWCOUNT_BIG. @@ROWCOUNT和@@ERROR变 ...