Leetcode 67 Add Binary
来源:互联网 发布:vscode react 调试 编辑:程序博客网 时间:2024/06/06 03:41
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) { reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); if(a.size()>b.size()) swap(a,b); while(a.size()<b.size()) a+='0'; int add=0; for(int i=0;i<a.size();i++) { int sum=add+a[i]+b[i]-'0'-'0'; b[i]=sum%2+'0'; add=sum/2; } if(add) b+='1'; reverse(b.begin(),b.end()); return b; }};
1 0
- [leetcode 67] Add Binary
- [LeetCode 67]Add Binary
- leetcode-67 Add Binary
- leetcode || 67、Add Binary
- LeetCode 67 Add Binary
- Add Binary - LeetCode 67
- LeetCode---(67) Add Binary
- leetcode[67]:Add Binary
- leetcode 67 Add Binary
- Leetcode# 67 Add Binary
- leetcode 67: Add Binary
- leetcode-67-Add Binary
- Leetcode#67||Add Binary
- [Leetcode]#67 Add Binary
- leetcode 67Add Binary
- Leetcode 67:Add Binary
- leetcode 67 Add Binary
- [leetcode 67] Add Binary
- iOS学习笔记 地图(二)MapKit框架
- IDE(intellij_idea)中安装lombok plugin
- cxf实现webservice服务端
- 安卓基础小技巧--(一)
- vim 显示行号
- Leetcode 67 Add Binary
- IE下判断IE版本的语句...[if lte IE 8]……[endif]
- NYOJ-677-碟战(最大流最小割)
- 接口和抽象类
- java发送邮件工具类
- HTTP 协议入门
- [Day7]什么是单例模式,如何理解mvc设计模式
- Some Notes
- 第四周项目6-多项式求和