문제 난이도 : Easy
문제 유형 : Data Structures - String
문제 설명 간략 :
두개의 binary string이 주어지고 둘의 binary string 합을 출력하라.
제약사항
- 1 <= a.length, b.length <= 10000
- a and b consist only of ‘0’ or ‘1’ characters.
- Each string does not contain leading zeros except for the zero itself.
자바 풀이
class Solution {
    public String addBinary(String a, String b) {
        String result = "";
        int s = 0;
        int i = a.length()-1;
        int j = b.length()-1;
        while(i >= 0 || j >= 0 || s ==1) {
            s += ((i >= 0)? a.charAt(i) - '0' : 0);
            s += ((j >= 0)? b.charAt(j) - '0' : 0);
            result = (char)(s % 2 + '0') + result;
            s = s/2;
            i--; j--;
        }
        return result;
    }
}
출처