Leetcode 67. Add Binary (Easy) (cpp)
来源:互联网 发布:stc89c52单片机简介 编辑:程序博客网 时间:2024/05/29 03:46
Leetcode 67. Add Binary (Easy) (cpp)
Tag: Math, String
Difficulty: Easy
/*67. Add Binary (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) { int i = a.size(), j = b.size(), carry = 0; string res; while (i > 0 || j > 0 || carry > 0) { int num1 = i > 0 ? a[(i--) - 1] - '0' : 0, num2 = j > 0 ? b[(j--) - 1] - '0' : 0; carry += num1 + num2; res = char(carry % 2 + '0') + res; carry /= 2; } return res; }};
0 0
- Leetcode 67. Add Binary (Easy) (cpp)
- 【leetcode】Add Binary[easy]
- [Leetcode 67, easy] Add Binary
- 【LeetCode】(67)Add Binary (Easy)
- <LeetCode><Easy> 67 Add Binary
- Leetcode 258. Add Digits (Easy) (cpp)
- Leetcode 415. Add Strings (Easy) (cpp)
- 67.LeetCode Add Binary(easy)[字符串 大数相加处理]
- Leetcode 110. Balanced Binary Tree (Easy) (cpp)
- Leetcode 257. Binary Tree Paths (Easy) (cpp)
- Leetcode 226. Invert Binary Tree (Easy) (cpp)
- 67. Add Binary [easy] (Python)
- 67.Add Binary(String-Easy)
- Leetcode OJ 67 Add Binary [Easy]
- LeetCode-Easy刷题(14) Add Binary
- [LeetCode]67.Add Binary
- LeetCode --- 67. Add Binary
- [Leetcode] 67. Add Binary
- commons-pool实战之 GenericObjectPool和GenericKeyedObjectPool
- jdk1.7和jdk1.8区别
- C语言getgroups()函数:获取组代码函数
- java递归实现二分查找算法
- java递归实现二分查找算法
- Leetcode 67. Add Binary (Easy) (cpp)
- Python解析excel文件并存入sqlite数据库
- 使用了google zxing作为二维码生成工具
- VMware安装CentOS以及CentOS的一些配置
- jedis针对三种redis工作模式的连接方式
- Edittext不可编辑可点击 & 解决Edittext第二次点击才有效
- cocos2dx 自动遍历class下所有cpp文件 区分win32和mac
- 几个著名java开源缓存系统的介绍
- 面试总结篇之Javascript(三)