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. ActiveMQ学习--002--Topic消息例子程序

    一.非持久的Topic消息示例 注意 此种方式消费者只能接收到 消费者启动之后,发送者发送的消息. 发送者 package com.lhy.mq.helloworld; import java.uti ...

  2. 我与GitHub的第一次——自制音乐文件修改器

    背景: 随机播放,所有的音乐播放器里面现在几乎都有这个功能吧.但是有没有发现,自己的播放器在选择随机播放的时候,经常会听到重复顺序的歌曲呢?反正我是有这样的感觉,无耐自己平时下的歌曲都是“歌手名—歌曲 ...

  3. 【数组】3Sum

    题目: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find al ...

  4. android-zip解压缩方法

    /** * 解压缩文件到指定的目录. * * @param unZipfileName * 需要解压缩的文件(带路径) * @param mDestPath * 解压缩后存放的路径 **/ publi ...

  5. 《Mysql技术内幕,Innodb存储引擎》——事物

    事物 事物中的操作要么都成功要么都不做,这是事物的目的,也是事物模型与文件系统的重要特征之一. 扁平事物(Flat Transactions) 所有操作都处于同一层次,要么都做要么都执行要么都回滚,无 ...

  6. nginx pcre错误

    以上错误是因为pcre的路径指定的不对,--with-pcre模块应该指向的是pcre解压后的源码包,而不是pcre的安装路径. ]$./configure --prefix=/data01/logs ...

  7. Chapter 3 Phenomenon——6

    A low oath made me aware that someone was with me, and the voice was impossible not to recognize. 某人 ...

  8. vue view 表单验证正常逻辑

    <template> <Form ref="formInline" :model="formInline" :rules="rule ...

  9. fiddler工作原理和设置代理问题

    1,什么是Fiddler Fiddler是一个http协议调试代理工具,它能够记录客户端和服务器之间的所有 HTTP请求,可以针对特定的HTTP请求,分析请求数据.设置断点.调试web应用.修改请求的 ...

  10. CentOS探索之路2---使用rpm安装JDK

    使用rpm安装jdk ​ 在前一Linux探索文章中http://www.cnblogs.com/Kidezyq/p/8782728.html,有关于通过yum指令安装原生OpenJDK的命令.当时有 ...