67. Add Binary
来源:互联网 发布:微商软件总代理 编辑:程序博客网 时间:2024/06/06 08:58
Given two binary strings, return their sum (also a binary string).
For example,
a = "11"
b = "1"
Return "100"
.
public class Solution { public String addBinary(String a, String b) { int m = a.length(); int n = b.length(); String res = ""; int carry = 0; int i = 0; while(i<m || i<n || carry!=0){ int x = (i<m) ? a.charAt(m - 1 - i) - '0' : 0; int y = (i<n) ? b.charAt(n - 1 - i) - '0' : 0; res = (x + y + carry)%2 + res; carry = (x + y + carry)/2; i++; } return res; }}
阅读全文
0 0
- [LeetCode]67.Add Binary
- LeetCode --- 67. Add Binary
- [Leetcode] 67. Add Binary
- [leetcode] 67.Add Binary
- 67. Add Binary
- 【leetcode】67. Add Binary
- 67. Add Binary
- [leetcode] 67.Add Binary
- [leetcode] 67. Add Binary
- 67. Add Binary
- 67. Add Binary
- 【Leetcode】67. Add Binary
- 67. Add Binary
- 67. Add Binary LeetCode
- 67. Add Binary
- 【LeetCode】67. Add Binary
- 67. Add Binary
- 67. Add Binary
- job命令
- 1. javascript继承的方式
- Redis链接方式
- TypeError: Fetch argument None has invalid type <class 'NoneType'>解决方案
- Lua学习笔记(1)-基础知识、表达式语法
- 67. Add Binary
- C语言中变量的作用域和生命周期
- meta标签的属性介绍
- 集成——Mac电脑上app自动化测试(Appium + xcode 8.2 + python)环境搭建
- swagger API 摆脱手写API的烦恼(ssm + swagger)
- mybatis疑难杂症之配置文件无限加载 Property 'configLocation' not specified, using default MyBatis Configuration
- 小米手机开启debug模式
- MySQL下载安装、配置与使用(win7x64)
- 104. Maximum Depth of Binary Tree