Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0 Star 0 Fork 0

徐云天/leetcode

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
_67.java 706 Bytes
Copy Edit Raw Blame History
徐云天 authored 2021-06-29 17:58 +08:00 . 增加67
public class _67 {
static class Solution {
public String addBinary(String a, String b) {
int i = a.length()-1,j = b.length()-1;
int flow = 0;
StringBuilder sb = new StringBuilder();
while(i >= 0 || j >= 0){
int x = i >= 0 ? a.charAt(i) -'0' : 0;
int y = j >= 0 ? b.charAt(j) -'0': 0;
char cur = (x + y + flow) % 2 == 0 ? '0' : '1';
flow = (x + y + flow) / 2;
sb.append(cur);
i--;
j--;
}
if(flow == 1){
sb.append('1');
}
return sb.reverse().toString();
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/xuyuntian/leetcode.git
git@gitee.com:xuyuntian/leetcode.git
xuyuntian
leetcode
leetcode
master