问题描述:

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.

很简单就是像写大数加法那样,代码如下

 class Solution {
public:
vector<int> plusOne(vector<int> &digits) {
int l=digits.size();
if(l==){
return digits;
}
if(l==){
if(digits[]!=){
digits[]++;
return digits;
}
else{
vector<int> v;
v.push_back();
v.push_back();
return v;
}
}
int flg=;
int temp=digits[l-]+;
if(temp>){
digits[l-]=;
flg=;
}
else{
digits[l-]=temp;
return digits;
}
for(int i=l-;i>=;i--){
int temp=digits[i]+;
if(temp>){
digits[i]=;
flg=;
}
else{
digits[i]=temp;
return digits;
}
}
if(flg){
//vector<int>::iterator it=;
digits.insert(digits.begin(),);
}
return digits;
}
};

【leetcode】plus One的更多相关文章

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

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

  2. 【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 ...

  3. 53. Maximum Subarray【leetcode】

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

  4. 27. Remove Element【leetcode】

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

  5. 【刷题】【LeetCode】007-整数反转-easy

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...

  6. 【刷题】【LeetCode】000-十大经典排序算法

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法

  7. 【leetcode】893. Groups of Special-Equivalent Strings

    Algorithm [leetcode]893. Groups of Special-Equivalent Strings https://leetcode.com/problems/groups-o ...

  8. 【leetcode】657. Robot Return to Origin

    Algorithm [leetcode]657. Robot Return to Origin https://leetcode.com/problems/robot-return-to-origin ...

  9. 【leetcode】557. Reverse Words in a String III

    Algorithm [leetcode]557. Reverse Words in a String III https://leetcode.com/problems/reverse-words-i ...

  10. 【LeetCode】数组--合并区间(56)

    写在前面   老粉丝可能知道现阶段的LeetCode刷题将按照某一个特定的专题进行,之前的[贪心算法]已经结束,虽然只有三个题却包含了简单,中等,困难这三个维度,今天介绍的是第二个专题[数组] 数组( ...

随机推荐

  1. [转]Tomcat----Neither the JAVA_HOME nor the JRE_HOME environment variable is defined

    对于使用IDE开发的程序员来讲,并不是所有人都对自己用来吃饭的工具了如指掌.常在阴沟跑,哪能不翻船.为此我把自己使用Tomcat/Eclipse的一些经验教训整理了一下,会陆续的贴出来,也许会帮到和我 ...

  2. Visual Studio与Chrome调试工具使用技巧

    VS: 1: Ctrl + Enter (在光标指定位置的上面添加一行,并将光标移至新添加行的行首位置) Ctrl + Shift + Enter (在光标指定位置的下面添加一行,并将光标移至新添加行 ...

  3. 【leetcode】Word Ladder II

      Word Ladder II Given two words (start and end), and a dictionary, find all shortest transformation ...

  4. HttpServletRequest中得到各种信息

    1.获得domain: StringBuffer url = request.getRequestURL(); String domain = url.delete(url.length() - re ...

  5. Java使用for循环打印乘法口诀(正倒左右三角形)

    代码1: public void test1(){ for(int i = 1; i < 10 ; i ++){ for(int k = 1; k < i ; k ++){ System. ...

  6. java 入门 第二季1

    (1). 类和对象(java 语言是面向对象的) 1). 类是对象的类型 具有相同的属性和方法的一组对象的集合 类:属性和方法 定义类: 类名 属性 方法 //class为关键字 2.定义类时,首字母 ...

  7. SAP打印出库单 新需求

    *&---------------------------------------------------------------------* *& Report  Z_SD_CKD ...

  8. 【关于服务器端SQL Server 2008的设置】 使其他客户端机可通过ODBC数据源可访问

    服务器系统:Server 2003 数据库:SQL Server 2005 服务器配置:开启服务:server.workstation(这两个服务对于提供局域网共享有很大作用) 关闭防火墙 开启gue ...

  9. FZU 2165 v11(最小重复覆盖)+ codeforces 417D Cunning Gena

    告诉你若干个(<=100)武器的花费以及武器能消灭的怪物编号,问消灭所有怪物(<=100)的最小花费...当然每个武器可以无限次使用,不然这题就太水了╮(╯▽╰)╭ 这题当时比赛的时候连题 ...

  10. Cuckoo for Hashing_双哈希表

    问题 B: Cuckoo for Hashing 时间限制: 1 Sec  内存限制: 64 MB提交: 24  解决: 12[提交][状态][讨论版] 题目描述 An integer hash ta ...