【LeetCode】Add Binary
来源:互联网 发布:专业视频制作软件 编辑:程序博客网 时间:2024/04/30 21:39
class Solution {public: string addBinary(string a, string b) { int aindex = a.size() - 1;int bindex = b.size() - 1;string c;int flag = 0,num;while (aindex>=0 && bindex>=0){num = a[aindex] - '0' + b[bindex] - '0'+flag;flag = num / 2;num %= 2;c = (char(num + '0')) + c;aindex--;bindex--;}while (aindex>=0){num = a[aindex] - '0' + flag;flag = num / 2;num %= 2;c = (char(num + '0')) + c;aindex--;}while (bindex >= 0){num = b[bindex] - '0' + flag;flag = num / 2;num %= 2;c = (char(num + '0')) + c;bindex--;}if (flag > 0){c = (char)(flag + '0') + c;}return c; }};
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
- 【Hadoop基础教程】6、Hadoop之单表关联查询
- 总结的一些json格式和对象/String/Map/List等的互转工具类
- Actionbar入门(二)
- 深入研究Android Handler机制
- 《AngularJS》5个实例详解Directive(指令)机制
- 【LeetCode】Add Binary
- 小毛驴(xml)试乘记(三):jQuery方法
- springmvc @RequestMapping不要写死
- Java复习--线程基本概念
- 零碎的
- 2015年 国家超级计算济南中心 工作日志
- 给EditText添加一个工具方法,使其支持仅保留到第N位小数
- 利用 onload 事件监控跨站资源
- OGG-02050 Not enough database memory to honor requested MAX_SGA_SIZE