1、题目描述

2、题目分析

使用string 的逆向指针,做二进制加法,注意进位问题就可以。

3、代码

 string addBinary(string a, string b) {

         string::reverse_iterator it_a = a.rbegin() ;
string::reverse_iterator it_b = b.rbegin() ; string s;
string s0 = "";
string s1 = "";
int up = ;
while( it_a != a.rend() && it_b != b.rend() ){
if( *it_a - '' + *it_b - '' + up == ){
s = s1 + s;
up = ;
}else if( *it_a - '' + *it_b - '' + up == ){
s = s0 + s;
up = ;
}else if( *it_a - '' + *it_b - '' + up == ){
s = s0 + s;
up=;
}else if( *it_a - '' + *it_b - '' + up == ){
s = s1 + s;
up = ;
}
++it_a ;
++it_b ;
} while( it_a != a.rend() ){
if( *it_a - '' + up == ){
s = s0 + s;
up = ;
}else if( *it_a - '' + up == ){
s = s1 + s;
up = ;
}else{
s = s0 + s;
up = ;
}
++it_a ;
} while( it_b != b.rend() ){
if( *it_b - '' + up == ){
s = s0 + s;
up = ;
}else if(*it_b - '' + up == ){
s = s1 + s;
up =;
}else{
s = s0 + s;
up = ;
}
++it_b;
} if( up == ){
s = s1 + s;
} return s; }

LeetCode 题解之Add Binary的更多相关文章

  1. # Leetcode 67:Add Binary(二进制求和)

    Leetcode 67:Add Binary(二进制求和) (python.java) Given two binary strings, return their sum (also a binar ...

  2. leetcode解题:Add binary问题

    顺便把之前做过的一个简单难度的题也贴上来吧 67. Add Binary Given two binary strings, return their sum (also a binary strin ...

  3. leetcode笔记:Add Binary

    一.题目描写叙述 Given two binary strings, return their sum (also a binary string). For example, a = "1 ...

  4. 【LeetCode】67. Add Binary 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 BigInteger类 模拟加法 日期 题目地址:h ...

  5. 【一天一道LeetCode】#67. Add Binary

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...

  6. leetcode题解2. Add Two Numbers

    题目: You are given two non-empty linked lists representing two non-negative integers. The digits are ...

  7. 【LeetCode】67. Add Binary

    题目: Given two binary strings, return their sum (also a binary string). For example,a = "11" ...

  8. LeetCode算法题-Add Binary(Java实现)

    这是悦乐书的第157次更新,第159篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第16题(顺位题号是67).给定两个二进制字符串,返回它们的总和(也是二进制字符串).输 ...

  9. 《LeetBook》LeetCode题解(2):Add Two Numbers [M]

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

随机推荐

  1. 我的Git教程 之 初始化本地库

    初始化本地库 前言:这个教程只适用于像我一样大致理解Git的原理,但是不太记得住Git命令的同学使用.所以具体原理只会提一下,具体可以参见Pro Git.同时,下面的操作需要先安装相应的Git工具,具 ...

  2. habase 报错 ERROR: Can't get master address from ZooKeeper; znode data == null

    方法一:查看日志报SessionExpiredException: KeeperErrorCode = Session expired for /hbase/master 所以是hbase 和 zoo ...

  3. 分区助手官网使用教程(专业版、绿色版和WinPE版)(图文详解)

    不多说,直接上干货! 详情见 http://www.disktool.cn/jiaocheng/index.html http://www.disktool.cn/jiaocheng/index2.h ...

  4. 【原】Ubuntu13.04安装、卸载Gnome3.8

    添加 GNOME 3 PPA(Personal Package Archives) 我们先给Ubuntu的Software Sources增加GNOME 3 PPA.这可以不用命令行就做到,但出于简单 ...

  5. MySQL的Sleep进程占用大量连接解决方法

    第一部分为产生大量sleep进程的原理及对应解决方法第二部分为设置wait_timeout值,有效减少sleep进程 ========================================= ...

  6. R语言常用包分类总结

    常用包: ——数据处理:lubridata ,plyr ,reshape2,stringr,formatR,mcmc: ——机器学习:nnet,rpart,tree,party,lars,boost, ...

  7. Druid连接池(三)

    十二.Druid缓存 连接Oracle数据库,打开PSCache,在其他的数据库连接池都会存在内存占用过多的问题,Druid是唯一解决这个问题的连接池. Oracle数据库下PreparedState ...

  8. css揭秘

    一:渐变 线性渐变(Linear Gradients)- 向下/向上/向左/向右/对角方向       background: linear-gradient(direction, color-sto ...

  9. Web 后端--PHP 与数据库的交互

    网页要处理数据,数据置于数据库之中.今天看了书,不能让知识遗忘,遂及时记下. 用 PHP  操作 MySQL ,实现数据的交换,还要多练练.... PS: 以下 mysql 字段与mysqli 字段皆 ...

  10. Linux进程管理 简介

    何为进程,我想这个问题大家再熟悉不过了吧,无非就是"执行中的程序"! 概念性的东西本文暂时忽略或者略微一提,详细信息还需要阅读相应的blog或专业书籍.(博主收藏了计算机相关的大量 ...