See More

package AddBinary; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; /** * User: Danyang * Date: 1/28/2015 * Time: 0:17 * * Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". */ public class Solution { /** * Reverse * @param a * @param b * @return */ public String addBinary(String a, String b) { List ret = new ArrayList<>(); if(a.length()>b.length()) { String t = a; a = b; b = t; } List lst_a = a.chars().map(e -> e-'0').boxed().collect(Collectors.toList()); List lst_b = b.chars().map(e -> e-'0').boxed().collect(Collectors.toList()); Collections.reverse(lst_a); Collections.reverse(lst_b); int carry = 0; for(int i=0; i