【LeetCode】066. Plus One
题目:
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.
You may assume the integer do not contain any leading zero, except the number 0 itself.
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 n = digits.size();
int carry = ;
for(int i = n - ; i >= ; --i){
int sum = digits[i] + carry;
carry = sum / ;
digits[i] = sum % ;
}
if(carry != )
digits.insert(digits.begin(), );
return digits;
}
};
【LeetCode】066. Plus One的更多相关文章
- 【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 ...
- 【刷题】【LeetCode】007-整数反转-easy
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...
- 【刷题】【LeetCode】000-十大经典排序算法
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法
- 【leetcode】893. Groups of Special-Equivalent Strings
Algorithm [leetcode]893. Groups of Special-Equivalent Strings https://leetcode.com/problems/groups-o ...
- 【leetcode】657. Robot Return to Origin
Algorithm [leetcode]657. Robot Return to Origin https://leetcode.com/problems/robot-return-to-origin ...
- 【leetcode】557. Reverse Words in a String III
Algorithm [leetcode]557. Reverse Words in a String III https://leetcode.com/problems/reverse-words-i ...
随机推荐
- java并发编程基础---Sky
1.线程及启动和终止 1.1 线程 -进程/优先级 操作系统调度的最小单元是线程,线程是轻量级进程. 线程优先级由setPriority(int)方法来设置,默认优先级是5,等级1~10.等级越高分的 ...
- 洛谷 P3674 小清新人渣的本愿
想看题目的戳我. 我刚开始觉得这道题目好难. 直到我从Awson大佬那儿了解到有一个叫做bitset的STL,这道题目就很容易被解开了. 想知道这个神奇的bitset的戳我. 这个题目一看就感觉是莫队 ...
- Python中为什么要使用线程池?如何使用线程池?
系统处理任务时,需要为每个请求创建和销毁对象.当有大量并发任务需要处理时,再使用传统的多线程就会造成大量的资源创建销毁导致服务器效率的下降.这时候,线程池就派上用场了.线程池技术为线程创建.销毁的开销 ...
- centos 时区正确,时间不对
centos6.5 里面 时区是 Asia/Shanghai ,但是 时间还是不对,在网上收集了如下做法:好像恢复了~~ (主要过程是: 查看各种设置,然后设置时间,最后更新本机时间,最后保持与时间 ...
- CentOS 7 巨大变动之 systemd 取代 SysV的Init
1 systemd是什么 首先systmed是一个用户空间的程序,属于应用程序,不属于Linux内核范畴,Linux内核的主要特征在所有发行版中是统一的,厂商可以自由改变的是用户空间的应用程序. ...
- linux基础part3
linux基础 一.linux基本命令归档命令. 1.归档的定义:归档就是把许多文件或目录打包成一个文件. 2.tar命令格式:tar [参数-cxtzjvfpPN] 打包文件名 文件或目录路径 ...
- 淘宝开源平台(taobao-code)使用
偶尔之下翻到的这个东西,瞬间觉得足以解决自己在开发过程中的版本控制问题.就注册了一个试试.先是在度娘上搜寻“淘code”,进入官网之后直接注册.然后构建自己的项目,上传代码就OK了. 一.搜寻“淘co ...
- 认识CoreData—使用进阶
之前两篇文章都比较偏理论,文字表达比较多一些,但都是干货!学习时先理解理论知识,才能更好的帮助后面的理解.在这篇文章中,将会涉及关于CoreData的一些复杂操作,这些操作会涉及分页查询.模糊查询.批 ...
- java中接口的概念及使用(补充final修饰符的使用)
接口 初期理解,可以是一个特殊的抽象类 当抽象类中的方法都是抽象的,那么该类可以通过接口的形式来表示 class 用于定义类 interface 用于定义接口 接口定义时,格式特点: 1.接口中常见的 ...
- path.join()和path.resolve()区别
一.区别 1.path.join() 方法使用平台特定的分隔符作为定界符将所有给定的 path 片段连接在一起,然后规范化生成的路径. 2.path.resolve() 方法将路径或路径片段的序列解析 ...