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

一个非负整数n按照从高到低的顺序将每一位放在数组中,然后n加1,返回加1后的数组。

注意进位的问题。

代码如下:

 class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
int size = digits.size();
int flag = ;
for(int i = size-; i >= ; i --)
{
digits[i] = digits[i] + flag;
flag = ;
if(digits[i] > )
{
digits[i] = ;
flag = ;
}
}
if(flag == )
{
digits.insert(digits.begin(),flag);
}
return digits;
}
};

leetcode 66的更多相关文章

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

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

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

  3. 2017-3-7 leetcode 66 119 121

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

  4. LeetCode 66. Plus One(加1)

    Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. Yo ...

  5. LeetCode(66)题解: Plus One

    https://leetcode.com/problems/plus-one/ 题目: Given a non-negative number represented as an array of d ...

  6. [LeetCode] 66. Plus One 加一

    Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The ...

  7. Java实现 LeetCode 66 加一

    66. 加一 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示 ...

  8. [LeetCode]66. 加一(数组)

    ###题目 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 ...

  9. Leetcode 66 Plus One STL

    题意让大数加1 我的做法是先让个位+1,再倒置digits,然后进位,最后倒置digits,得到答案. class Solution { public: vector<int> plusO ...

随机推荐

  1. studio-引入外来包

    参考: http://stackoverflow.com/questions/16588064/how-do-i-add-a-library-project-to-the-android-studio ...

  2. 不能向Github提交某一類型的文件

    之前在github上建了6個project,但是其中有一個不能提交jar文件,其他的都可以.後來發現原來在項目中有一個叫.gitignore的文件,其他項目里的都是/bin,但是那個不能提交jar的項 ...

  3. 谈Objective-C Block的实现

    来源:http://blog.devtang.com/blog/2013/07/28/a-look-inside-blocks/ 前言 这里有关于block的5道测试题,建议你阅读本文之前先做一下测试 ...

  4. JDBC中的事务-Transaction

    事务-Transaction 某些情况下我们希望对数据库的某一操作要么整体成功,要么整体失败,经典的例子就是支付宝提现.例如我们发起了支付宝到银行卡的100元提现申请,我们希望的结果是支付宝余额减少1 ...

  5. python wechat_sdk间接性的出现错误OfficialAPIError: 40001,说access_token已过期或者不是最新的。

    原因是部署django时使用了多进程,每个进程都会去请求access_token,只有最新的那个有效

  6. ms sqlserver 系列之如何查看数据链接数

    [转]如何查看SQL SERVER数据库当前连接数 1.通过管理工具开始->管理工具->性能(或者是运行里面输入mmc)然后通过添加计数器添加 SQL 的常用统计然后在下面列出的项目里面选 ...

  7. Jquery 对象转json ,Json转对象。兼容浏览器。

    引入jquery 转json库 [ 文件大小为2.2K] <script type="text/javascript" src="https://jquery-js ...

  8. 【转】find命令

    Linux中find常见用法示例·find path -option [ -print ] [ -exec -ok command ] {} \;find命令的参数: pathname: find命令 ...

  9. IntelliJ IDEA设置字符编码为UTF-8

    File->Settings->Editor->File Encodings IDE Encoding: UTF-8 Project Encoding: UTF-8

  10. ReferenceError: Sys is not defined

    项目框架MVC3 <form action="/Organization/Update" method="post" onclick="Sys. ...