Leetcode 67 Add Binary
来源:互联网 发布:window10 共享端口 编辑:程序博客网 时间:2024/06/02 00:01
Leetcode 67 Add Binary
include <string>using namespace std;class Solution {public: string addBinary(string a, string b) { int i = a.length() - 1; int j = b.length() - 1; int sum = 0; string result; while(i >= 0 || j >= 0) { sum += i >= 0 ? (a[i] - '0') : 0; sum += j >= 0 ? (b[j] - '0') : 0;//sum: 00/01/10/11 result = ((sum & 1) ? "1" : "0") + result;//&1 : the last bit of sum 0/1 sum >>= 1;//right one bit is carry i --; j --; } return sum ? "1" + result : result;//if sum == 1,need to add the last carry bit }};
阅读全文
0 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
- Sql 2014 企业版 还原数据库时, 报错: 操作错误, 或 No backupset selected to be restored
- tp3 生成验证码时,代码无误但显示不了的解决方法
- 关于tensorflow入门代码
- 1578:分歧终端机
- MySql中的CHAR、VARCHAR、TEXT选用
- Leetcode 67 Add Binary
- opencv依赖项
- 箭头函数
- excel相关系列(5)----文件上传遇到的fakepath的问题
- 1854: H-曲线长度
- hdu6208
- ThreadLocal的一点理解
- 线程函数的设计以及MsgWaitForMultipleObjects函数的使用要点
- EXTJS 使用Ajax跨域上传文件