67. Add Binary
My Submissions QuestionEditorial Solution
Total Accepted: 81992 Total Submissions: 299902 Difficulty: Easy
Given two binary strings, return their sum (also a binary string).

For example,
a = “11”
b = “1”

Return “100”.

class Solution {
public:string addBinary(string a, string b) {string s;int lena = a.length() - 1;int lenb = b.length() - 1;int temp = 0;char c;while(lena >= 0 && lenb >= 0) {c = (a[lena] - '0') + (b[lenb] - '0') + temp + '0';temp = 0;if((c - '0') >= 2) {temp = 1;c = c - 2;}s = c + s;lena--;lenb--;}while(lena >= 0) {c = (a[lena] - '0') + temp + '0';temp = 0;if((c - '0') >= 2) {temp = 1;c = c - 2;}s = c + s;lena--;}while(lenb >= 0) {c =(b[lenb] - '0') + temp + '0';temp = 0;if((c - '0') >= 2) {temp = 1;c = c - 2;}s = c + s;lenb--;}if(temp == 1) {s = '1' + s;}return s;}
};

LeetCode 67. Add Binary相关推荐

  1. [LeetCode]67.Add Binary

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

  2. leetcode 67 Add Binary

    Add Binary Total Accepted: 46815 Total Submissions: 189215 My Submissions Given two binary strings, ...

  3. [LeetCode] 67. Add Binary Java

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

  4. LeetCode刷题记录4——67. Add Binary(easy)

    LeetCode刷题记录4--67. Add Binary(easy) 目录 LeetCode刷题记录4--67. Add Binary(easy) 题目 语言 思路 后记 题目 今天这题是与字符串相 ...

  5. 67. Add Binary 二进制加法leetcode

    67 Add Binary 二进制加法leetcode 题目描述 方法1: 方法2: 题目描述 Given two binary strings a and b, return their sum a ...

  6. leetcode python3 简单题67. Add Binary

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第六十七题 (1)题目 英文: Given two binary strings, ...

  7. Java for LeetCode 067 Add Binary

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

  8. 67. Add Binary

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

  9. 67. Add Binary

最新文章

  1. 第3关:4位快速加法器设计
  2. jquery实现表格中点击相应行变色功能
  3. springboot+jps+druid项目搭建
  4. 2020年五面蚂蚁、三面拼多多、字节跳动最终拿offer入职拼多多
  5. 【001】python数据分析与挖掘
  6. 活到老,学到老!各大厂数据库技术解决方案来了
  7. 别以为真懂Openstack: 虚拟机创建的50个步骤和100个知识点(1)
  8. matlab 创建同型矩阵_以经典同型样式创建新地图
  9. 中州韵输入法 linux 小鹤双拼,「Rime 鼠须管」小鹤双拼配置指南
  10. 苹果手机数据线充不了电_自动洗地机充不了电,洗地机厂家
  11. 阿里云服务器公网带宽下载上传速度及测速Ping值测试工具
  12. 开关量模块——一对多无线传输
  13. App逆向|一个案例教你如何进行APP逆向
  14. 第一性原理:戳中问题本质的人是怎么思考的?
  15. php页面会返回状态200,服务器404错误页面http状态返回值为200的原因解析
  16. Lib Dll在VS2008下的编译和使用-持续更新,欢迎拍砖
  17. 信号量机制中的down和up函数
  18. 三国杀开源系列之三106@365
  19. Linux笔记之浅析文件编辑器vim
  20. linux 命令学习大全,初学者必备

热门文章

  1. 难过的时候看一看 再坏能有多坏!
  2. 求一个截取字符的正则表达式
  3. C#.NET 权限管理系统组件 - 大数据读写分离实现的例子
  4. WatchStor观察:冰岛身陷困境也不会停止数据中心项目
  5. Selenium2.0功能测试之唯一元素的定位
  6. [20160803]另类行迁移.txt
  7. 修改linux系统时间的方法(date命令)
  8. 云架构指挥调度平台技术方案建议书
  9. C#中反射的使用(How to use reflect in CSharp)(3)Emit的使用
  10. 如何让Snippet Compiler 2008 支持linq