Leetcode题解(22)
66. Plus One
题目

这题很简单,直接代码:
class Solution {
public:
vector<int> plusOne(vector<int> &digits) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
int a = ;
vector<int> ans;
vector<int>::iterator it;
for(int i = digits.size() - ;i >= ;i--)
{
it = ans.begin();
int b = (a + digits[i]) % ;
a = (a + digits[i]) / ;
ans.insert(it, b);
}
if(a != )
{
it = ans.begin();
ans.insert(it, a);
}
return ans;
}
};
------------------------------------------------------------------------------------分割线--------------------------------------------------------------
67. Add Binary
题目

直接代码
class Solution {
public:
string addBinary(string a, string b) {
int lenA,lenB;
lenA = a.length();
lenB = b.length();
string res="";
if ( == lenA)
{
return b;
}
if ( == lenB)
{
return a;
}
int ia=lenA-,ib=lenB-;
int count=,temp;//进位
char c;
while (ia>=&&ib>=)
{
temp = a[ia]-''+b[ib]-''+count;
count = temp/;
c = temp%+'';
res = c+res;
ia--;
ib--;
}
while (ia>=)
{
temp = a[ia]-''+count;
count = temp/;
c = temp%+'';
res = c+res;
ia--;
}
while (ib>=)
{
temp = b[ib]-''+count;
count = temp/;
c = temp%+'';
res = c+res;
ib--;
}
if(count != )
{
c=count+'';
res = c+res;
}
return res;
}
};
Leetcode题解(22)的更多相关文章
- [LeetCode 题解]:Path Sum
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Given a bi ...
- [LeetCode 题解]: Roman to Interger
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Given a ro ...
- [LeetCode题解]: Sort Colors
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Given an a ...
- [LeetCode 题解]: Maximum Subarray
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Find the c ...
- [LeetCode 题解]:Gas Station
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 There are ...
- [LeetCode 题解]: plusOne
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Given a no ...
- [LeetCode 题解]: ZigZag Conversion
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 The string ...
- LeetCode题解汇总(包括剑指Offer和程序员面试金典,持续更新)
LeetCode题解汇总(持续更新,并将逐步迁移到本博客列表中) LeetCode题解分类汇总(包括剑指Offer和程序员面试金典) 剑指Offer 序号 题目 难度 03 数组中重复的数字 简单 0 ...
- LeetCode题解分类汇总(包括剑指Offer和程序员面试金典,持续更新)
LeetCode题解汇总(持续更新,并将逐步迁移到本博客列表中) 剑指Offer 数据结构 链表 序号 题目 难度 06 从尾到头打印链表 简单 18 删除链表的节点 简单 22 链表中倒数第k个节点 ...
- 【LeetCode题解】二叉树的遍历
我准备开始一个新系列[LeetCode题解],用来记录刷LeetCode题,顺便复习一下数据结构与算法. 1. 二叉树 二叉树(binary tree)是一种极为普遍的数据结构,树的每一个节点最多只有 ...
随机推荐
- 添加事务后 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type available
今天遇到了一个奇怪的问题 在没添加事务之前 所有的代码都是好的 , 当我添加了事务之后, 代码报错 org.springframework.beans.factory.NoSuchBeanDef ...
- 关于Android WebView上传文件的解决方案
我们在开发需求的时候,难免会接入一下第三方的H5页面,有些H5页面是具有上传照片的功能,Android 中的 WebView是不能直接打开文件选择弹框的 接下来我讲简单提供一下解决方案,先说一下思路 ...
- iOS开发-AFNetworking参数和多文件同时上传【多文件上传】
1. 前言 在项目开发中,我们经常需要上传文件,例如:上传图片,上传各种文件,而有时也需要将参数和多个文件一起上传,不知道大家的项目中遇到了没有,我在最近的项目中,就需要这样的一个功能:同时上传参数. ...
- readfile & file_get_contents异同
记录一下:应用memcache时,准备把整个文件缓存到内存中,遇到了比较奇怪的事情,因为最初使用readfile来读取文件,结果这个函数返回一个字节数,而不是一个字符串,于是文件没办法再输出,最后使用 ...
- vue路由跳转 vue-router的使用
1.路由对象和路由匹配 路由对象,即$router会被注入每个组件中,可以利用它进行一些信息的获取.如 属性 说明 $route.path 当前路由对象的路径,如'/view/a' $rotue.pa ...
- 浅析前端开发中的 MVC/MVP/MVVM 模式
MVC,MVP和MVVM都是常见的软件架构设计模式(Architectural Pattern),它通过分离关注点来改进代码的组织方式.不同于设计模式(Design Pattern),只是为了解决一类 ...
- 插入排序的性能测试对比(C与C++实现)
一.概述: [标题]学生成绩管理的设计与实现 [开发语言]C.C++ [主要技术]结构体.STL [基本功能]实现对学生成绩类的基本操作:增加.删除.查询.排序 [测试数据]功能测试:按提示输入5组正 ...
- centos7基础学习第一天
Linux是一个操作系统: 智能手机,Android和ios.Windows: 网站.游戏.QQ.微信等都是运行在Linux系统之上的应用:客户端.服务器端交互的: Linux的起源: Linux之前 ...
- Jmeter连接mysql数据库
1.下载 MySQL JDBC driver,并拷贝到jmeter的lib目录下. 2.创建JDBC Connection Configuration 需要填入的信息: Variable Name:M ...
- iptables使用实践
1.iptables 本质上是一组规则,报文从端口接收到之后,按照规则的顺序进行匹配,一旦匹配上则执行动作,后续就不再匹配. 2.为了体现出优先级,iptable分为4个表,5个链,如下: 优先级顺序 ...