[LeetCode]67. Add Binary
来源:互联网 发布:简易电路图绘制软件 编辑:程序博客网 时间:2024/06/07 17:17
https://leetcode.com/problems/add-binary/
字符串形式的二进制数字相加
public class Solution { public String addBinary(String a, String b) { StringBuilder sb = new StringBuilder(); int add = 0; int i = a.length() - 1; int j = b.length() - 1; while (i >= 0 || j >= 0) { int sum = add; if (i >= 0) { sum += a.charAt(i--) - '0'; } if (j >= 0) { sum += b.charAt(j--) - '0'; } sb.append(sum % 2); add = sum / 2; } if (add != 0) { sb.append(add); } return sb.reverse().toString(); }}
0 0
- [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
- LeetCode 67. Add Binary
- LeetCode *** 67. Add Binary
- leetcode 67. Add Binary
- 【leetcode】67.Add Binary
- LeetCode 67. Add Binary
- LeetCode-67.Add Binary
- openstack Neutron源码分析(三)------linuxbridge-agent
- java volatile变量
- 【HDU1693】Eat the Trees(插头DP)
- 面试题19:二叉树的镜像
- USACO 2.1 海明码 Hamming Codes
- [LeetCode]67. Add Binary
- 这儿有自学前端开发的吗-
- java线程实战:多线程下载(上)
- 面试题20:顺时针打印矩阵
- 陈寅恪的最后20年 - 笔记
- Linux 高级IO
- Oracle11g rac常用命令
- 面试题21:包含min函数的栈
- 仿IOS底部弹出效果