problem

Plus One

code

class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
vector<int> res;
int carry = ;
int sum = ;
int mod = ;
int i = digits.size()-;
while(carry && i>=)
{
sum = digits[i] + carry;
carry = sum / ;
mod = sum % ;
res.push_back(mod);
i--;
}
if(carry && i<) res.push_back(carry);
for( ; i>=; i--)
{
res.push_back(digits[i]);
}
reverse(res.begin(), res.end());
return res; }
};

注意可能有进位,而且可能有多个进位,另外注意最高位有进位的情况。

参考

1.leetcode;

【leetcode】66-PlusOne的更多相关文章

  1. 【LeetCode】66. Plus One 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数九 采用进位 日期 [LeetCode] 题目地址 ...

  2. 【LeetCode】66 & 67- Plus One & Add Binary

    66 - Plus One Given a non-negative number represented as an array of digits, plus one to the number. ...

  3. 【LeetCode】66. 加一

    66. 加一 知识点:数组: 题目描述 给定一个由 整数 组成的 非空 数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 ...

  4. 【LeetCode】66. Plus One

    题目: Given a non-negative number represented as an array of digits, plus one to the number. The digit ...

  5. 【LeetCode】66. Plus One (2 solutions)

    Plus One Given a non-negative number represented as an array of digits, plus one to the number. The ...

  6. 【LEETCODE】66、字符串分类,hard级别,题目:32,72,76

    package y2019.Algorithm.str.hard; import java.util.Stack; /** * @ProjectName: cutter-point * @Packag ...

  7. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  8. 【Leetcode】Pascal&#39;s Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  9. 53. Maximum Subarray【leetcode】

    53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...

  10. 27. Remove Element【leetcode】

    27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...

随机推荐

  1. SecureCRT修改显示行数

    Scrollback buffer应该是保留的行数,初始值500,修改成自己想要的数值保存即可. 参考:http://blog.csdn.net/w410589502/article/details/ ...

  2. 把旧系统迁移到.Net Core 2.0 日记(6) MapRoute/Area/ViewPath

    我想实现 http://localhost:5000/{moduleName}/{controller}/{action}/{id?} 这样的url. 有2个方法 方法1: 在路由里设置多个modul ...

  3. Java中的equals和==的差别 以及Java中等价性和同一性的讨论

    ==对基本数据类型比较的是值,对引用类型比较的是地址 equals()比较的是对象的数据的引用 等价性原理: 自反性    x.equals(x)为true 对称性    x.equals(y) 为t ...

  4. django_rq无法监听两个队列问题

    django_rq是为django集成redis队列,这个用的少,一般会选择celery,没办法项目中用到了.用起来很简单,配置可以参考官方文档:https://pypi.org/project/dj ...

  5. SpringMVC中文乱码的解决办法

    中文乱码分类: (1)按照请求分类: GET请求乱码 POST请求乱码 (2)按照乱码位置分类 从前台传到后台的数据乱码(存储到数据库中的数据乱码) 从后台传到前台的数据乱码(显示在页面的数据乱码) ...

  6. caffe,Inception v2 Check failed: top_shape[j] == bottom[i]->shape(j)

    使用Caffe 跑 Google 的Inception V2 对输入图片的shape有要求,某些shape输进去可能会报错. Inception model中有从conv和pooling层concat ...

  7. Iterator,迭代器模式,C++描述

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  8. Oracle与MySQL的SQL语句区别

    2 表 2.1 创建表(同) create table tableName( columnName1 int, columnName2 int ) 2.2 删除表(异) MySQL: drop tab ...

  9. ngnix笔记

    ngnix可通过-s 参数控制,如quit正常退出:reload重载配置文件,具体参考:http://nginx.org/en/docs/switches.html ngnix的指令解释请参考这里:h ...

  10. 栈回溯简单实现(x86)

    0x01  栈简介  首先局部变量的分配释放是通过调整栈指针实现的,栈为函数调用和定义局部变量提供了一块简单易用的空间,定义在栈上的变量不必考虑内存申请和释放.只要调整栈指针就可以分配和释放内存.   ...