结合着这篇http://www.cnblogs.com/Michael2397/p/8027782.html自己完全实现了,顿时感觉到刷题有套路啊
public class TwoSumbin { public String addStrings(String num1, String num2) { if(num1==null||num2==null){ return num1==null?num2:num1; } StringBuffer string = new StringBuffer(); int carry=0; for (int i = num1.length()-1,j=num2.length()-1; i>=0||j>=0||carry>0; i--,j--) { int sum = 0; sum +=(i>=0)?num1.charAt(i)-'0':0; sum +=(j>=0)?num2.charAt(j)-'0':0; sum += carry; carry = sum/10; sum = sum%10; string.append(sum); } return string.reverse().toString(); } }