problem

Plus One

code

  1. class Solution {
  2. public:
  3. vector<int> plusOne(vector<int>& digits) {
  4. vector<int> res;
  5. int carry = ;
  6. int sum = ;
  7. int mod = ;
  8. int i = digits.size()-;
  9. while(carry && i>=)
  10. {
  11. sum = digits[i] + carry;
  12. carry = sum / ;
  13. mod = sum % ;
  14. res.push_back(mod);
  15. i--;
  16. }
  17. if(carry && i<) res.push_back(carry);
  18. for( ; i>=; i--)
  19. {
  20. res.push_back(digits[i]);
  21. }
  22. reverse(res.begin(), res.end());
  23. return res;
  24.  
  25. }
  26. };

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

参考

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. SQL SERVER版本补丁体系及升级

    首先了解几个定义: RTM : 表示 Release to Manufacturing ,这是产品的原始发布版本,当从光盘或 MSDN 下载的默认版本.不过现在下载 SQL Server 版本时,也有 ...

  2. sublime ctags跳转函数使用

    sublime 点击某函数 按F12可以查到相关函数文件 正题: 1.下载ctags客户端文件 http://prdownloads.sourceforge.net/ctags/ctags58.zip ...

  3. fiddler 抓包配置

    1.我们安装完成后点击运行程序,就可以看到如下图,这是进入Fildder的第一个界面. 2.安装好后打开fiddler→选择 Tools >Fildder Options > Https ...

  4. 人机交互之QQ拼音

    随着电脑系统的不断更新,电脑自带的系统输入法也越来越适应广大群众了,那为什么其他的输入法还能占有大量的用户呢? 首先系统输入法是面向大众的,个性化方面略显不足. 其次系统输入法功能不够全面,比如说手写 ...

  5. AdminLTE 文档

    一个基于 bootstrap 的轻量级后台模板,这个前端界面个人感觉很清爽,对于一个大后端的我来说,可以减少较多的时间去承担前端的工作但又必须去独立去完成一个后台系统开发的任务,并且,文档还算比较齐全 ...

  6. VS 中常用的一些快捷键

    一.代码自动对齐 CTRL+K+F     二.撤销/反撤销 1.撤销---使用组合键“Ctrl+Z”进行撤销操作 2.反撤销---使用组合键“Ctrl+Y”进行反撤销操作 三.调用智能提示 使用组合 ...

  7. 【原创】<Debug> QT头文件

    [Error] No such file or directory [Solution] 参考: http://blog.csdn.net/donglynn/article/details/21804 ...

  8. HTTP协议详细解析

    HTTP协议详解 HTTP协议(HyperText Transfer Protocol,超文本传输协议)是因特网上应用最为广泛的一种网络传输协议,所有的WWW文件都必须遵守这个标准. HTTP是一个基 ...

  9. Android : 网络adb配置及有线端口占用解决方法

    一.调试环境: Android Debug Bridge version 1.0.40: Nexus6P平板(Android 8.0系统): 二.网络ADB调试: 1. Android设备除了用有线u ...

  10. transclude

    http://jsfiddle.net/ospatil/A969Z/157/ transclude :true  允许指令内部的dom元素, 保留到 自定义指令的template属性里的含有 ng-t ...