Java Big Integer solution

  • 0

    I don't like this solution, but it is what came to mind first.

    import java.math.BigInteger;
    public class Solution {
        public String addBinary(String a, String b) {
           BigInteger a_val = new BigInteger(a, 2);
           BigInteger b_val = new BigInteger(b, 2);
           BigInteger sum = a_val.add(b_val);
            return sum.toString(2);

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.