LeetCode Oj 67. Add Binary
来源:互联网 发布:怪物猎人p3多玩数据库 编辑:程序博客网 时间:2024/06/03 10:55
67. Add Binary
- Total Accepted: 92800
- Total Submissions: 327327
- Difficulty: Easy
Given two binary strings, return their sum (also a binary string).
For example,
a = "11"
b = "1"
Return "100"
.
Subscribe to see which companies asked this question
Show Similar Problems
Have you met this question in a real interview?
Yes
No
Discuss Pick One
class Solution {public: string addBinary(string a, string b) { reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); string ans=""; int big=0; int len=max(a.length(),b.length()); int x; int y; for(int i=0;i<len;i++) { if(i>=a.length()) x=0; else x=a[i]-'0'; if(i>=b.length()) y=0; else y=b[i]-'0'; ans=ans+(char)((x+y+big)%2+'0'); big=x+y+big>1 ? 1:0; } if(big) ans=ans+"1"; reverse(ans.begin(),ans.end()); return ans; }};
0 0
- <LeetCode OJ> 67. Add Binary
- LeetCode Oj 67. Add Binary
- LeetCode OJ:Add Binary
- LeetCode OJ - Add Binary
- LeetCode OJ Add Binary
- Leetcode OJ 67 Add Binary [Easy]
- [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
- 67. Add Binary LeetCode
- 【LeetCode】67. Add Binary
- leetcode--67. Add Binary
- leetcode 67. Add Binary
- 加载项目中配置文件的两种方式
- bapi (物料主数据导入)的部分基础用法
- 结构风险最小和VC维理论的解释
- 在线文档查看网站地址
- Linux【4】
- LeetCode Oj 67. Add Binary
- synchronized (syncObj)
- 关于的select问题
- glClipPlane剪裁平面
- iTunes Connect新应用发布流程
- jquery学习网站
- Linux【5】
- winscp 连接 linux
- 回文字符串问题