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 | 29 | 30 | 31 |
Tags
- 코딩테스트
- jQuery
- 스프링
- JS
- map
- 유레카
- Spring
- GIT
- leetcode
- gitlab
- 프로그래머스
- STS
- docker
- spring boot
- spring security
- JavaScript
- 비동기
- IntelliJ
- Java
- 자바스크립트
- OAuth
- EUREKA
- date
- map()
- 도커
- 자바
- SpringBoot
- 스프링 클라우드
- Spring Cloud
- 스프링부트
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