Can BigInteger be used in this question?


  • -2
    S
    import java.math.BigInteger;
    
    public class Solution {
        public String addBinary(String a, String b) {
            if("".equals(a.trim())){
    			if("".equals(b.trim())){
    				return "";
    			}else{
    				return b.trim();
    			}
    		}else{
    			if("".equals(b.trim())){
    				return a.trim();
    			}else{
    				BigInteger ba = new BigInteger(a.trim(),2);
    				BigInteger bb = new BigInteger(b.trim(),2);
    				BigInteger sum = ba.add(bb);
    
    				return sum.toString(2);
    			} 
    		}
        }
    }

Log in to reply
 

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