@@ -0,0 +1,1456 @@
+package com.yan.leetcode;%0A%0Aimport org.junit.Test;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.LinkedList;%0Aimport java.util.List;%0A%0A/**%0A * Add Binary%0A *%0A * @author jingyangyan%0A * @version 1.0%0A * @create 2016-08-31 12:15%0A */%0Apublic class AddBinary %7B%0A%0A    @Test%0A    public void test() %7B%0A        System.out.println(addBinary(%2211%22, %221%22));%0A        StringBuilder sb = new StringBuilder();%0A        sb.insert(0, 1);%0A        sb.insert(0, 2);%0A        System.out.println(sb.toString());%0A    %7D%0A%0A    public String addBinary(String a, String b) %7B%0A        StringBuilder sb = new StringBuilder();%0A        int sub = Math.abs(a.length() - b.length());%0A        int ai = 0, bi = 0, ahead = 0;%0A        if (a.length() %3E b.length()) %7B%0A            for (int i = a.length() - 1; i %3E= 0; i--) %7B%0A                ai = a.charAt(i) - '0';%0A                bi = i - sub %3E= 0 ? b.charAt(i - sub) - '0' : 0;%0A                sb.insert(0, (ahead + ai + bi) %25 2);%0A                ahead = (ahead + ai + bi) / 2;%0A            %7D%0A            if (ahead %3E 0)%0A                sb.insert(0, ahead);%0A        %7D else %7B%0A            for (int i = b.length() - 1; i %3E= 0; i--) %7B%0A                bi = b.charAt(i) - '0';%0A                ai = i - sub %3E= 0 ? a.charAt(i - sub) - '0' : 0;%0A                sb.insert(0, (ahead + ai + bi) %25 2);%0A                ahead = (ahead + ai + bi) / 2;%0A            %7D%0A            if (ahead %3E 0)%0A                sb.insert(0, ahead);%0A        %7D%0A%0A        return sb.toString();%0A    %7D%0A%7D%0A

add binary