Leetcode 66 Plus One STL
题意让大数加1
我的做法是先让个位+1,再倒置digits,然后进位,最后倒置digits,得到答案。
class Solution {
public:
vector<int> plusOne(vector<int> &digits) {
digits[digits.size() -]++; //个位+1
reverse(digits.begin(),digits.end());//倒置digits
for(vector<int>::size_type i = ; i < digits.size() - ; ++i){//除了最高位,进位
if(digits[i] >= ){
digits[i] -= ;
digits[i+] ++;
}
}
if(digits[digits.size() - ] >= ){//最高位进位
digits[digits.size() - ] -= ;
digits.push_back();
}
reverse(digits.begin(),digits.end());//倒置digits
return digits;
}
};
Leetcode 66 Plus One STL的更多相关文章
- 前端与算法 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 290 Word Pattern STL
Leetcode 205 Isomorphic Strings的进阶版 这次是词组字符串和匹配字符串相比较是否一致 请使用map来完成模式统计 class Solution { public: boo ...
- 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 之外,这个整数不会以零开头. 示 ...
随机推荐
- HttpModule的一些初步认识
新建一个类 ValidaterHttpModuleEvents继承管道接口 IHttpModule,代码如下 public class ValidaterHttpModuleEvents:IHttpM ...
- 音痴又音痴的LT (vector)
http://acm.nyist.net/JudgeOnline/problem.php?pid=1261 分析:若是每次都想用sort继而来查第k个数,那会T的特别惨~ C++内置函数upperbo ...
- mysql学习-windows下绿色版mysql安装问题解决办法
1.下载绿色版mysql 从该地址http://dev.mysql.com/downloads/mysql/ 中选择windows的版本,选择下载. 2.将下载的压缩包解压. 3.将根目录下的my-d ...
- unreal3的viewport和client
名字里带viewport/client的类不少,以及相关的类: FViewportFrame.FViewport FViewportClient/UScriptViewportClient/UGame ...
- webapi返回json格式,并定义日期解析格式
1.webapi返回json格式 var json = config.Formatters.JsonFormatter; json.SerializerSettings.PreserveReferen ...
- Struts2中请求参数的接收方式和ModelDriven机制及其运用
odelDriven 为什么需要ModelDriven 所谓ModelDriven,意思是直接把实体类当成页面数据的收集对象.比如,有实体类User如下: package cn.com.leadfar ...
- c语言中动态数组的建立
一维动态数组的创建,这个比较简单,直接上代码 #define _CRT_SECURE_NO_DEPRECATE #include<stdio.h> #include<stdlib.h ...
- UIMenuController 实现长按显示自定义菜单功能
这段时间在集成使用融云聊天功能的时候,想自定义消息cell的长按的菜单,在网上查了查,这是根据 UIMenuController 实现的.具体代码如下,我是使用一个btn实现的 首先创建一个btn,并 ...
- html5新特性之音频、视频
1.视频 标签video video标签的属性 属性 描述 autoplay 视频就绪后自动播放 preload 视频在页面加载时加载 loop 视频播放完成后循环播放 controls 显示控件 s ...
- myfocus焦点库的引用
1.在Html中引入相关的文件:引入风格文件(js/css/jq) 2.创建myFocus标准的Html的结构并填充内容 <div id="picBox"> <d ...