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)是一种极为普遍的数据结构,树的每一个节点最多只有 ...
随机推荐
- RMQ问题第一弹
今天,我给大家分享一下我在学习 RMQ 问题过程中对该问题的理解. RMQ (Range Minimum/Maximum Query ):中文名为"区间最值查询".RMQ 问题指的 ...
- java集合系列——Map介绍(七)
一.Map概述 0.前言 首先介绍Map集合,因为Set的实现类都是基于Map来实现的(如,HashSet是通过HashMap实现的,TreeSet是通过TreeMap实现的). 1:介绍 将键映射到 ...
- 非常有用的css使用总结
积小流以成江海,很多东西你不总结就不是你的东西 常用css总结: /*设置字体*/ @font-face { font-family: 'myFont'; src: url('../font/myFo ...
- express简介
Express 是一个简洁而灵活的 node.js Web应用框架, 提供了一系列强大特性帮助你创建各种 Web 应用,和丰富的 HTTP 工具. 使用 Express 可以快速地搭建一个完整功能的网 ...
- SqlServer与Linq 无限递归目录树且输出层级
ALTER VIEW [dbo].[view_TreeLevel] AS WITH cte AS ( SELECT a.ModuleID , a.Module_Name , a.Module_Desc ...
- PPLB条码打印
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- wpf 画刷的分类
System.Windows.Media.Brush最上一层画刷 System.Windows.Media.GradientBrush 线性画刷 ,下层主要有两种画刷 System.Windows. ...
- JAVA常用API(Date、DateFormat、Calendar、System、Math、基本数据类型包装类)
注:本文所有内容均属个人见解,如有错误望各位大佬好心指点批评,不胜感激 本章重点单词: parse:解析 format:格式化 pattern:模式 amount:数量 filed :领域 1.Dat ...
- 人工智能 tensorflow框架-->简介及安装01
简介:Tensorflow是google于2015年11月开源的第二代机器学习框架. Tensorflow名字理解:图形边中流动的数据叫张量(Tensor),因此叫Tensorflow 既 张量流动 ...
- [置顶]
win10 uwp 参考
态度随意申请专栏,没想到通过 看了我的博客,都是在别的大神博客看到,然后修改他们的 我看到的大神博客 东邪独孤 http://www.cnblogs.com/tcjiaan/ 老周,买了他的<W ...