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. [MySQL] 常用SQL技巧--18.5

    1.正则表达式使用 MySQl利用REGEXP命令,提供正则表达式功能. 例子:select 'abcdef' REGEXP '^a'; select 'efg' REGEXP '[^XYZ]'; 2 ...

  2. Apache2 CGI demo

    1. 修改 httpd.conf  配置 <IfModule alias_module> ScriptAlias /cgi-bin/ "/usr/local/apache2/cg ...

  3. Apache2 添加登陆用户名和密码

    1. 修改httpd.conf, 对要做认证的目录进行设置<Directory "/usr/local/var/www">   Options Indexes Foll ...

  4. oProfile 学习

    oProfile工具可以分析CPU的负载量 只要对目标程序加上 -g 后重新编译,即可用oProfile进行分析 例如在测试apache的性能时, 增加 -g 编译选项[crifan@localhos ...

  5. ruby 字符串学习笔记3

    ascii转字符或者字符串转ascii "a".ord # => 97 "!".ord # => 33 "\n".ord # = ...

  6. web性能测试的新利器 - Gatling 介绍

    转载:http://www.51testing.com/html/10/26810-852956.html 最近发现了一个新的性能测试工具Gatling,貌似比Jmeter还好玩.这几天就先简单介绍一 ...

  7. struts (三)

    1. <action name="test" class="com.gc.Test"> <result name="success& ...

  8. MongoDB基本操作命令

    由于工作需要,笔者这两天使用了一下MongoDB.真的很不习惯!但是确实好用,命令比mysql和sqlserver简单很多.在这里整理一些MongoDB的基本操作命令分享出来. 客户端的安装就不说了, ...

  9. 浅谈Java的包装类

    一.什么是Java包装类 所谓Java包装类,就是将Java中的8种基本数据类型分别包装成为类的形式.包装类与基本数据类型的对应关系如下表所示. 基本数据类型 包装类 byte Byte short ...

  10. [ Office 365 开发系列 ] 开发模式分析

    前言 本文完全原创,转载请说明出处,希望对大家有用. 在正式开发Office 365应用前,我们先了解一下Office 365的开发模式,根据不同的应用场景,我们选择最适合的开发模式. 阅读目录 Of ...