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的更多相关文章

  1. LeetCode OJ 题解

    博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...

  2. Leetcode 简略题解 - 共567题

    Leetcode 简略题解 - 共567题     写在开头:我作为一个老实人,一向非常反感骗赞.收智商税两种行为.前几天看到不止两三位用户说自己辛苦写了干货,结果收藏数是点赞数的三倍有余,感觉自己的 ...

  3. 前端与算法 leetcode 66. 加一

    目录 # 前端与算法 leetcode 66. 加一 题目描述 概要 提示 解析 解法一 解法二 算法 # 前端与算法 leetcode 66. 加一 题目描述 给定一个由整数组成的非空数组所表示的非 ...

  4. CFEducational Codeforces Round 66题解报告

    CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...

  5. LeetCode 算法题解 js 版 (001 Two Sum)

    LeetCode 算法题解 js 版 (001 Two Sum) 两数之和 https://leetcode.com/problems/two-sum/submissions/ https://lee ...

  6. leetcode & lintcode 题解

    刷题备忘录,for bug-free 招行面试题--求无序数组最长连续序列的长度,这里连续指的是值连续--间隔为1,并不是数值的位置连续 问题: 给出一个未排序的整数数组,找出最长的连续元素序列的长度 ...

  7. 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 ...

  8. LeetCode一句话题解

    深度优先搜索 人生经验 1. 需要输出所有解.并由于元素集有重复元素,要求返回的结果需要去重的情况,可考虑使用值对应数量的map,然后分别考虑依次取不同数量该值的可能. LeetCode39 题目:给 ...

  9. 2017-3-7 leetcode 66 119 121

    今天纠结了一整天============================================================== leetcode66 https://leetcode.c ...

随机推荐

  1. linux实时查看更新日志命令

    很多时候在调试生成或正式平台服务器的时候想查看实时的日志输出,在Linux中可以使用tail 或 watch来实现. 比如我们项目中有个 app.log 的日志文件,我们普通读取都使用 vi app. ...

  2. 最短路POJ 1062 昂贵的聘礼

    C - 昂贵的聘礼 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit St ...

  3. Android几秒后自动关闭dialog

    代码改变世界 Android几秒后自动关闭dialog AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext()); b ...

  4. 【2018.10.15】WZJ笔记(数论)

    1. 证明:对于任意质数$p\gt 3$,$p^2-1$能被$24$整除. 证:平方差公式,$p^2-1 = (p-1)(p+1)$. 再把$24$分解质因数$2^3*3$. 三个相邻的自然数中至少有 ...

  5. Tomcat 调优技巧

    Tomcat 调优技巧:1.Tomcat自身调优: ①采用动静分离节约Tomcat的性能: ②调整Tomcat的线程池: ③调整Tomcat的连接器: ④修改Tomcat的运行模式: ⑤禁用AJP连接 ...

  6. 使用腾讯互动直播 遇到的坑 'GLIBC_2.14' not found 问题解决

    第一.查看系统glibc版本库 strings /lib64/libc.so.6 |grep GLIBC_ 这里我们可以看到系统中最新的版本是2.12,这里我们升级2.14. 第二.下载和安装glib ...

  7. java 汉字保存到mysql 乱码

    保存之前正常,插入数据乱码 确认jsp mysql编码都确定为utf8 在连接数据库是加上编码 jdbc:mysql://localhost:3306/test?useUnicode=true& ...

  8. HDU 4771 BFS + 状压

    Stealing Harry Potter's Precious Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  9. Scrapy学习-9-FromRequest

    用FromRequest模拟登陆知乎网站 实例 默认登陆成功以后的请求都会带上cookie # -*- coding: utf-8 -*- import re import json import d ...

  10. zTree 用法小例

    插件地址:链接:http://pan.baidu.com/s/1jHVtyZ0 密码:7kee <select id="getTree" resultType="j ...