LeetCode:Add Binary
来源:互联网 发布:免费的数据挖掘软件 编辑:程序博客网 时间:2024/06/07 13:39
Total Accepted: 64222 Total Submissions: 252110 Difficulty: Easy
Given two binary strings, return their sum (also a binary string).
For example,
a = "11"
b = "1"
Return "100"
.
code:
class Solution {public: string addBinary(string a, string b) { int carry=0; int i=a.size()-1,j=b.size()-1; string ret=""; while(i!=-1 || j!=-1 || carry) { carry += i>=0 ? a[i--]-'0':0; carry += j>=0 ? b[j--]-'0':0; ret = char(carry % 2 + '0') + ret; carry /= 2; } return ret; }};
0 0
- LeetCode: Add Binary
- [Leetcode] Add Binary
- LeetCode Add Binary
- Leetcode: Add Binary
- [Leetcode] Add Binary
- LeetCode : Add Binary
- LeetCode Add Binary
- [LeetCode] Add Binary
- leetcode 58: Add Binary
- leetcode Add Binary
- [LeetCode] Add Binary
- 【leetcode】Add Binary
- [LeetCode]Add Binary
- [leetcode]Add Binary
- LeetCode-Add Binary
- [leetcode] Add Binary
- LeetCode - Add Binary
- leetcode:Add Binary
- ubuntu 搭建 Lamp
- C语言实现链表之双向链表(十)删除任意结点
- Linux下打开大文件方法探究
- 分布式发布订阅消息系统 Kafka
- eclipse 提交至github服务器时遇到的默认账号问题
- LeetCode:Add Binary
- android 在自定义的view中接收不到onkeydown事件
- IIS下搭建FTP服务器
- Java之command模式
- [JavaScript/JQuery] jQuery图片缩小效果
- Android第三方开源PullToRefresh(系列1)
- android back 返回机制的几种解决方案
- Java操作Access数据库
- Java继承和多态简述