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. centos下yum安装wget失败

    执行了yum -y install wget后得到下面的提示 Failed to set locale, defaulting to C Loaded plugins: fastestmirror L ...

  2. 查看linux的版本

    1. uname -a ~$ uname -a Linux lubuntu-Vostro-A840 3.19.0-73-generic #81-Ubuntu SMP Tue Oct 18 16:02: ...

  3. db link的查看创建与删除

    1.查看dblink select owner,object_name from dba_objects where object_type='DATABASE LINK'; 或者 select * ...

  4. ORACLE 查看数据库中有哪些表

    SELECT TABLE_NAME FROM USER_TABLES ORDER BY TABLE_NAME;

  5. [Flex] ButtonBar系列——简单布局

    <?xml version="1.0" encoding="utf-8"?> <!--通过layout属性,设置ButtonBar布局--&g ...

  6. mysql如何给汉字按照首字母顺序排序

    select * from 表名 order by convert(列明 USING gbk) COLLATE gbk_chinese_ci asc

  7. delphi TServerSocket阻塞线程单元 实例

    TServerSocket阻塞线程单元,希望对你有所帮助.需要注意的是:1.如果你使用TServerSocket的stNonBlocking模式,重写TServerClientThread线程时要重载 ...

  8. sql server 2008 r2 中的oracle发布使用笔记

    sql server 2008 r2 中的oracle发布功能,能够将oracle数据库作为发布服务器,将oracle中的数据自动同步到sql server 数据库中,在新建oracle发布前确保sq ...

  9. C++primer 练习15.15

    // 15_15.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  10. 避免多层回调,Node.js异步库Async使用(series)

    未使用Async之前coffeescript写的代码: exports.product_file_add = (req,res) -> if !req.param('file_id') retu ...