【leetcode】66-PlusOne
problem
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的更多相关文章
- 【LeetCode】66. Plus One 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数九 采用进位 日期 [LeetCode] 题目地址 ...
- 【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. ...
- 【LeetCode】66. 加一
66. 加一 知识点:数组: 题目描述 给定一个由 整数 组成的 非空 数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 ...
- 【LeetCode】66. Plus One
题目: Given a non-negative number represented as an array of digits, plus one to the number. The digit ...
- 【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 ...
- 【LEETCODE】66、字符串分类,hard级别,题目:32,72,76
package y2019.Algorithm.str.hard; import java.util.Stack; /** * @ProjectName: cutter-point * @Packag ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【Leetcode】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
- 27. Remove Element【leetcode】
27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...
随机推荐
- webapp检测安卓app是否安装并launch
1. cordova插件 1)查看所有已安装的安卓app https://www.npmjs.com/package/cordova-plugin-packagemanager A simple pl ...
- 验证ip地址正则
验证ip地址: ^(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])(\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)){3}$ 析:(1\d{ ...
- 微信小程序 无限加载 上拉加载更多
加载更多,其实就是再次向接口发送请求,把返回的数据,追加到渲染页面的数组里的过程,具体实现实例如下: demo.js // pages/project/project.js const app = g ...
- py 正在爬取第%d页的美眉图
#coding=utf-8import reimport requestsfrom bs4 import BeautifulSoupnums = 1num = 1while True: url = & ...
- 转 Deep Learning for NLP 文章列举
原文链接:http://www.xperseverance.net/blogs/2013/07/2124/ 大部分文章来自: http://www.socher.org/ http://deepl ...
- learning ddr write leveling
- Tomcat错误:getOutputStream() has already been called for this response
使用weblogic部署时,没有报错.客户现场使用tomcat后报错. 在tomcat下jsp中出现此错误一般都是在jsp中使用了输出流(如输出图片验证码,文件下载等),没有妥善处理好的原因.具体的原 ...
- RabbitMQ 设置消息的TTL(过期时间)
我们在RabbitMQ中发布消息时,在代码中有两种方法设置某个队列的消息过期时间: 1.针对队列来说,可以使用x-message-ttl参数设置当前队列中所有消息的过期时间,即当前队列中所有的消息过期 ...
- leetcode python 005
## 给定字符串,寻找最长回文子串## 单回文,双回文 def findh(s): ## 单回文 ld,l=[],len(s) if len(s)<3: re ...
- python三目运算符
python 可通过 if 语句来实现三目运算符的功能,因此可以近似地把这种if语句当成三目运算符.作为三目运算符的 if 语句的语法格式如下: True_statements if expressi ...