题解 | #大数加法#
大数加法
https://www.nowcoder.com/practice/11ae12e8c6fe48f883cad618c2e81475
import java.util.*; class Solution { public String solve(String num1,String num2){ StringBuilder s=new StringBuilder(); int i=num1.length()-1,j=num2.length()-1;int add=0; for(;i>=0||j>=0||add!=0;i--,j--) { int n1=i>=0?num1.charAt(i)-'0':0; int n2=j>=0?num2.charAt(j)-'0':0; s.append((n1+n2+add)%10); add=(n1+n2+add)/10; } s.reverse(); return s.toString(); } }