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. 一、I/O操作(File文件对象)

    一.File类 Java里,文件和文件夹都是用File代表 1.使用绝对路径或者相对路径创建File对象 使用绝对路径或者相对路径创建File对象 package File; import java. ...

  2. MSSQL2012中SQL调优(SQL TUNING)时CBO支持和常用的hints

    虽然当前各关系库CBO都已经非常先进和智能,但因为关系库理论和实现上的限制,CBO在特殊场景下也会给出次优甚至存在严重性能问题的执行计划,而这些场景中,有一部分只能或适合通过关系库提供的hints来进 ...

  3. rexec/rlogin/rsh介绍

    服务 是否需要密码 是否明文 功能 端口 rexec 是 是 远程执行命令 512 rlogin 是 是 远程登录得到shell 513 rsh 是 是 可远程执行命令,也可远程登录得到shell 5 ...

  4. linux网络操作 netstat命令

    关闭与启动网卡 ifdown 网卡设备名 #禁用该网卡设备 ifup网卡设备名 #启用该网卡设备 查看网络状态 netstat  命令 ​ -t 列出tcp协议端口 -u 列出udp协议端口 -n 不 ...

  5. firstchild.data与childNodes[0].nodeValue意思

    x.firstchild.data:获取元素第一个子节点的数据: x.childNodes[0]::获取元素第一个子节点; x.childNodes[0].nodeValue.:也是获取元素第一个子节 ...

  6. DeepLearning4J

    http://blog.csdn.net/nysyxxg/article/details/52554734

  7. flask项目结构(一)mariadb

    简介: 本文主要是根据自己所学,创建一个flask项目,使用sqlalchemy,alembic,mariadb,bootstrap,APScheduler,selenium,request…………技 ...

  8. (C/C++学习笔记) 十九. 模板

    十九. 模板 ● 模板的基本概念 模板(template) 函数模板:可以用来创建一个通用功能的函数,以支持多种不同形参,进一步简化重载函数的函数体设计. 语法: template <<模 ...

  9. SWAP 简介

    swap 交换分区,是存放在内存当中的临时数据(断电数据丢失) SWAP作用:当内存不足时会导致系统挂了,SWAP就是起到一个临时内存的作用,当内存不足时SWAP充当临时内存,防止系统挂掉

  10. 基于session做的权限控制

    一直听说做权限将登陆信息放在session中,实际也说不太出个所以然来,幸运在工作当中接触到了对应的代码的copy. 实现思路: 类似于粗粒度的权限控制 将权限控制的文件按包分隔好,对应的url前缀也 ...