[LeetCode] Add Binary
来源:互联网 发布:手机淘宝6.10旧版本 编辑:程序博客网 时间:2024/05/21 10:19
Add from tail to head
class Solution {public: string addBinary(string a, string b) { if(a.length()<b.length()) { string t = a; a = b; b = t; } int carry = 0; string result = a; int i=a.length()-1, j=b.length()-1; while(j>=0) { int tmp = (a[i]-'0') + (b[j]-'0') + carry; carry = tmp/2; result[i] = tmp%2 + '0'; i--;j--; } while(i>=0) { int tmp = (a[i]-'0') + carry; carry = tmp/2; result[i] = tmp%2 + '0'; i--; } if(carry==0) return result; result = "1"+result; return result; }};
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
- Longest Substring Without Repeating Characters -- LeetCode
- codeforces#231_div2_B Very Beautiful Number 高精度枚举
- ldr和adr在使用标号表达式作为操作数的区别
- 面试题
- java面试题---算法2
- [LeetCode] Add Binary
- 网站许久不管为什么排名越来越好
- Stanford - Cryptography I - Week 1-2 Programming Assignment
- Access denied for user 'root'@'localhost' (using password: YES)
- mysql_connect报告”No such file or directory”错误的解决方法
- Call to undefined function mb_detect_encoding()错误的处理方法
- Apache Prefork、Worker和Event三种MPM
- Leetcode LinkedList Summary
- linux下挂载硬盘!