LeetCode 67. Add Binary
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相关推荐
- [LeetCode]67.Add Binary
[题目] Given two binary strings, return their sum (also a binary string). For example, a = "11&qu ...
- leetcode 67 Add Binary
Add Binary Total Accepted: 46815 Total Submissions: 189215 My Submissions Given two binary strings, ...
- [LeetCode] 67. Add Binary Java
题目: Given two binary strings, return their sum (also a binary string). For example, a = "11&quo ...
- LeetCode刷题记录4——67. Add Binary(easy)
LeetCode刷题记录4--67. Add Binary(easy) 目录 LeetCode刷题记录4--67. Add Binary(easy) 题目 语言 思路 后记 题目 今天这题是与字符串相 ...
- 67. Add Binary 二进制加法leetcode
67 Add Binary 二进制加法leetcode 题目描述 方法1: 方法2: 题目描述 Given two binary strings a and b, return their sum a ...
- leetcode python3 简单题67. Add Binary
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第六十七题 (1)题目 英文: Given two binary strings, ...
- Java for LeetCode 067 Add Binary
Given two binary strings, return their sum (also a binary string). For example, a = "11" b ...
- 67. Add Binary
Given two binary strings, return their sum (also a binary string). For example, a = "11" b ...
- 67. Add Binary
最新文章
- 第3关:4位快速加法器设计
- jquery实现表格中点击相应行变色功能
- springboot+jps+druid项目搭建
- 2020年五面蚂蚁、三面拼多多、字节跳动最终拿offer入职拼多多
- 【001】python数据分析与挖掘
- 活到老,学到老!各大厂数据库技术解决方案来了
- 别以为真懂Openstack: 虚拟机创建的50个步骤和100个知识点(1)
- matlab 创建同型矩阵_以经典同型样式创建新地图
- 中州韵输入法 linux 小鹤双拼,「Rime 鼠须管」小鹤双拼配置指南
- 苹果手机数据线充不了电_自动洗地机充不了电,洗地机厂家
- 阿里云服务器公网带宽下载上传速度及测速Ping值测试工具
- 开关量模块——一对多无线传输
- App逆向|一个案例教你如何进行APP逆向
- 第一性原理:戳中问题本质的人是怎么思考的?
- php页面会返回状态200,服务器404错误页面http状态返回值为200的原因解析
- Lib Dll在VS2008下的编译和使用-持续更新,欢迎拍砖
- 信号量机制中的down和up函数
- 三国杀开源系列之三106@365
- Linux笔记之浅析文件编辑器vim
- linux 命令学习大全,初学者必备
热门文章
- 难过的时候看一看 再坏能有多坏!
- 求一个截取字符的正则表达式
- C#.NET 权限管理系统组件 - 大数据读写分离实现的例子
- WatchStor观察:冰岛身陷困境也不会停止数据中心项目
- Selenium2.0功能测试之唯一元素的定位
- [20160803]另类行迁移.txt
- 修改linux系统时间的方法(date命令)
- 云架构指挥调度平台技术方案建议书
- C#中反射的使用(How to use reflect in CSharp)(3)Emit的使用
- 如何让Snippet Compiler 2008 支持linq