[LeetCode66]Plus One
题目:
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.
一个整数按位存在一个数组中array[0]为最高位
代码:
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
int size = digits.size();
if (digits[size - ] != )
{
digits[size - ]++;
return digits;
}
else
{
for (int i = size - ; i >= ; --i)
{
if (++digits[i] > )
{
digits[i] = ;
}
else
break;
}
if (digits[] == )
{
digits[] = ;
digits.push_back();
}
}
return digits;
}
};
[LeetCode66]Plus One的更多相关文章
- leetcode-66.加一
leetcode-66.加一 题意 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个 ...
- LeetCode----66. Plus One(Java)
package plusOne66; /* Given a non-negative number represented as an array of digits, plus one to the ...
- [Swift]LeetCode66. 加一 | Plus One
Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The ...
- leetCode66:加一
/** * @param {number[]} digits * @return {number[]} */ var plusOne = function(digits) { if(digits[di ...
- 【leetcode-66】 加一
给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 1: 输入 ...
- leetcode66
public class Solution { public int[] PlusOne(int[] digits) { ]; < ) { digits[digits.Length - ]++; ...
- 2017-3-7 leetcode 66 119 121
今天纠结了一整天============================================================== leetcode66 https://leetcode.c ...
随机推荐
- win 开机 Microsoft corparation 滚动栏
在easybcd里设置 后保存!
- hdu 5056Boring count
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5056 题目大意:就是问在子串中每一个小写字母出现次数不超过k次的个数,注意子串是连续的子串.. . ...
- 自编Ps教程—我的ps图片赞赏
上篇讲述了主要的ps概念和操作,这里不再讲述了,主要的操作学好了,其它的都简单,下面我会把我闲暇时间天马行空的小作品上穿,以供大家闲暇时间或者工作累了的时候赞赏! 以后还会在这里上传哦!喜欢就收藏吧! ...
- 读取生产环境go语言的最佳实践展示
近期看了一篇关于go产品开发最佳实践的文章,go-in-procution.作者总结了他们在用go开发过程中的非常多实际经验,我们非常多事实上也用到了.鉴于此,这里就简单的写写读后感,兴许我也争取能将 ...
- 组件-------(一)redis系列--安装部署redis+实现redis分布式缓存 java+Spring+redis
目的:解决单机session不能共享问题,插入查询数据库时间效率问题,实现分布式缓存. 准备材料:Redis 下载链接 http://pan.baidu.com/s/1dEGTxvV 相关jar包如果 ...
- sqlserver安全加固
sqlserver2012安装好以后必要的安全加固,不然非常多DBA的信息普通账户登录后都能够读取到. --use [master] --GO --DENY VIEW SERVER STATE ...
- 【POJ3159】Candies 裸的pqspfa模版题
不多说了.就是裸的模版题. 贴代码: <span style="font-family:KaiTi_GB2312;font-size:18px;">#include & ...
- 组队赛第二场:字符串哈希+DP
长春现场赛 HDU 4821 思路:这题周赛的时候没做出来,有点可惜了.要是当时记起来unsigned long long自己主动取模,然后提醒一下大帝的话,后续大帝就能过了. 唉,导致让他取了好多 ...
- IIS架构与HTTP请求处理流程
IIS架构与HTTP请求处理流程 Windows操作系统中的IIS负责提供互联网服务,一台运行了IIS的计算机可以看成是一台Web服务器. Windows XP SP2 中IIS主版本号为5,Wind ...
- spring的长处 ioc aop
spring 的长处? 1.减少了组件之间的耦合性 ,实现了软件各层之间的解耦 2.能够使用easy提供的众多服务.如事务管理,消息服务等 3.容器提供单例模式支持 4.容器提供了AOP技术,利用它非 ...