Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- JavaScript
- docker
- 비동기
- IntelliJ
- STS
- jQuery
- 자바
- Java
- SpringBoot
- 유레카
- EUREKA
- 스프링
- 프로그래머스
- 스프링부트
- map
- map()
- GIT
- 스프링 클라우드
- 코딩테스트
- gitlab
- OAuth
- Spring Cloud
- date
- leetcode
- 도커
- spring boot
- Spring
- spring security
- 자바스크립트
- JS
Archives
- Today
- Total
RATSENO
[Leetcode P67]2진수 더하기 본문
public class P67 {
private static String addBinary(String a, String b) {
StringBuilder sb = new StringBuilder();
int i = a.length() - 1;
int j = b.length() -1;
int carry = 0;
while (i >= 0 || j >= 0) {
int sum = carry;
if (j >= 0){
sum += b.charAt(j--) - '0';
}
if (i >= 0){
sum += a.charAt(i--) - '0';
}
sb.append(sum % 2);
carry = sum / 2;
}
if (carry != 0){
sb.append(carry);
}
return sb.reverse().toString();
}
public static void main(String[] args) {
String s = addBinary("1001", "1001");
}
}'DEV > 코딩테스트 문제풀기' 카테고리의 다른 글
| [Leetcode P70]피보나치 수열 (0) | 2021.03.22 |
|---|---|
| [JAVA]프로그래머스(level1) - 체육복 (0) | 2020.03.18 |
| [Leetcode]Valid Parentheses (0) | 2020.03.16 |
| [Leetcode]Longest Common Prefix (0) | 2020.03.16 |
| [Leetcode]Roman to Integer (0) | 2020.03.16 |
Comments