LeetCode - 66. Plus One(0ms)
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.
The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.
You may assume the integer does not contain any leading zero, except the number 0 itself.
Example 1:
- Input: [1,2,3]
- Output: [1,2,4]
- Explanation: The array represents the integer 123.
Example 2:
- Input: [4,3,2,1]
- Output: [4,3,2,2]
- Explanation: The array represents the integer 4321.
- class Solution {
- public:
- vector<int> plusOne(vector<int>& digits) {
- int s = digits.size();
- int flag = ;
- if(digits[] == ) {
- if(digits[s - ] == ) {
- for(int i = ; i < s - ; i++) {
- if(digits[i] == ) {
- continue;
- }
- else {
- flag = ;
- break;
- }
- }
- if(flag == ) {
- vector<int> res(s + );
- res[] = ;
- for(int i = ; i < s; i++)
- res[i] = ;
- return res;
- }
- }
- }
- if(digits[s - ] == ) {
- vector<int> res(s);
- res[s - ] = ;
- int car = ;
- for(int i = s - ; i >= ; i--) {
- res[i] = digits[i] + car;
- if(car == ) {
- if(res[i] == )
- res[i] = ;
- else
- car = ;
- }
- }
- return res;
- }
- else {
- vector<int> res(digits);
- res[s - ] = digits[s - ] + ;
- return res;
- }
- }
- };
LeetCode - 66. Plus One(0ms)的更多相关文章
- 前端与算法 leetcode 66. 加一
目录 # 前端与算法 leetcode 66. 加一 题目描述 概要 提示 解析 解法一 解法二 算法 # 前端与算法 leetcode 66. 加一 题目描述 给定一个由整数组成的非空数组所表示的非 ...
- LeetCode—66、88、118、119、121 Array(Easy)
66. Plus One Given a non-negative integer represented as a non-empty array of digits, plus one to th ...
- 2017-3-7 leetcode 66 119 121
今天纠结了一整天============================================================== leetcode66 https://leetcode.c ...
- leetcode 66
66. Plus One Given a non-negative number represented as an array of digits, plus one to the number. ...
- LeetCode 66. Plus One(加1)
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. Yo ...
- LeetCode(66)题解: Plus One
https://leetcode.com/problems/plus-one/ 题目: Given a non-negative number represented as an array of d ...
- [LeetCode] 66. Plus One 加一
Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The ...
- Java实现 LeetCode 66 加一
66. 加一 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示 ...
- [LeetCode]66. 加一(数组)
###题目 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 ...
随机推荐
- TridentState分析
public class TridentState { TridentTopology _topology; Node _node; protected TridentState(TridentTop ...
- JS JavaScript事件循环机制
区分进程和线程 进程是cpu资源分配的最小单位(系统会给它分配内存) 不同的进程之间是可以同学的,如管道.FIFO(命名管道).消息队列 一个进程里有单个或多个线程 浏览器是多进程的,因为系统给它的进 ...
- Vue nodejs商城项目-商品的分页、排序、筛选
.分页 ,要查第3页的数据,则跳过2*8条数据,然后返回8条数据. 在实现滚动加载时,页面刚一加载完成并不需要请求所有数据,当用户下拉到页面底部时,再去请求数据并拼接到商品数据列表中. 通过vue-i ...
- oracle 的分页查询与mysql 的分页查询
oracle 的分页查询: select * from (select o.*,rownum rn from Persons o) where rn >40 and rn <=60 : ...
- Qt学习交流(广告)
最近全面学习QT与c++,希望同行能够指教,于是打算建个群QQ群:85439482,欢迎大家,本群主要专注于QT皮肤库积累,软件架构以及标准c++学习.
- django-orm简记
首先orm是什么? orm-------->对象关系映射 专业性解释网上一大推,随便搜搜就能了解大概.在我理解(通俗):一个类 ----- 数据库中一张表 类属性 ----- 数据表中的字段名 ...
- 第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛--D-psd面试
链接:https://www.nowcoder.com/acm/contest/90/D 来源:牛客网 1.题目描述 掌握未来命运的女神 psd 师兄在拿了朝田诗乃的 buff 后决定去实习. 埃森哲 ...
- 【vlan-hybird】
根据项目要求搭建号拓扑图如下: 分别配置pc1-5的ip地址: 配置交换机sw1: 配置交换机sw2
- Post 和 Get的区别?
Post方法: 1. POST 请求的数据不会被缓存 2. Post请求的内容放置在HTML header中,用户是看不到这个过程的.所以是比较安全的 3. Post请求的数据大小没有限制 Get方法 ...
- 使用virtual安装Windows系列操作系统总结
最近在安装Windows操作系统的过程中,发现总是报错,无法安装成功,后来经过不断地摸索,发现根本的问题在于镜像,所以在以后的大文件传输下载后,一定要校验其MD5值是否与源文件一致,需要的朋友可以联系 ...