问题描述:

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. phpcms新闻轮播图实现

    首页如果有新闻的轮播图,点击图片可以进入相关的新闻.因为已经使用外部js轮播插件,所以想不修改插件进行轮播 我用的js插件是yx-rotaion插件,配合phpcms的get工具箱对新闻进行读取并抽取 ...

  2. apache开启虚拟主机localhost无法访问

    今天在集成环境下配虚拟主机,没想到虚拟主机开启后,localhost竟然无法访问了,解决办法是这样的: 实例一,Apache 配置localhost虚拟主机步骤 1,用记事本打开apache目录下ht ...

  3. poj 1572

    一道字符串替换的题目. 题意:给你2*n组字符串,一个是规则,一个是替换的结果. 字符串的题目,确实麻烦,有些细节不处理好就是wa. 这里我提供1组数据 intput 1 abcdef a abcde ...

  4. varchar 和 nvarchar 的区别和使用

    区别: 1.nvarchar 不管是一个字符还是一个汉字,都存为2个字节.varchar 汉字是两个字节,其它字符为1个字节. 2.nvarchar(n):包含n个字符的可变长度Unicode字符数据 ...

  5. php调用c/c++的一种方式

    php调用c/c++有很多方式,最常用的是通过tcp或者http去调用,通过发送请求去调用c/c++编写的cgi/fastcgi来实现,另外php还有一种直接执行外部应用程序的方式,这种方式会影响到系 ...

  6. FastReport经验

    FastReport经验 1.FastReport中如果访问报表中的对象? 可以使用FindObject方法. TfrxMemoView(frxReport1.FindObject(’memo1′)) ...

  7. 警告: 程序集绑定日志记录被关闭(IIS7 64位系统)

    部署一个.NET程序在IIS7服务器,出现如下信息: 说明: 执行当前 Web 请求期间,出现未处理的异常.请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息. 异常详细信息: S ...

  8. intel 面试总结

    昨天面了intel的Android部门,基无意外,面试的效果不是很好,很多问题没有回答上来,看来如果要进intel这种大公司光靠SJTU光环是远远不够的,必须要有真才实学.面试的还是一位交大学长,本科 ...

  9. Cuckoo for Hashing_双哈希表

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

  10. jQuery中attr()方法用法实例

    本文实例讲述了jQuery中attr()方法用法.分享给大家供大家参考.具体分析如下: 此方法设置或返回匹配元素的属性值. attr()方法根据参数的不同,功能也不同. 语法结构一: 获取第一个匹配元 ...