题解 | #大数加法#
大数加法
https://www.nowcoder.com/practice/11ae12e8c6fe48f883cad618c2e81475
class Solution {
public:
string solve(string s, string t) {
string ret;
int count = 0;
int i = s.size()-1;
int j = t.size()-1;
while(i>=0 || j>=0 || count)
{
if(i>=0) count += s[i--] - '0';
if(j>=0) count += t[j--] - '0';
ret.push_back((count%10)+'0');
count /= 10;
}
reverse(ret.begin(),ret.end());
return ret;
}
};
查看21道真题和解析