标签:turn har pre src bsp http inf for ima
题目:
解答:
1 class Solution { 2 public: 3 string addStrings(string num1, string num2) 4 { 5 int la = num1.size(); 6 int lb = num2.size(); 7 8 string sum = la > lb ? num1 : num2; 9 10 int overflow = 0; 11 12 for (int i = 0; i < sum.size(); i++) 13 { 14 char an = i < la ? num1[la - i - 1] : ‘0‘; 15 char bm = i < lb ? num2[lb - i - 1] : ‘0‘; 16 int bit = an - ‘0‘ + bm - ‘0‘ + overflow; 17 overflow = bit / 10; 18 sum[sum.size() - i - 1] = bit % 10 + ‘0‘; 19 } 20 if (overflow) 21 { 22 sum = ‘1‘ + sum; 23 } 24 25 return sum; 26 } 27 };
标签:turn har pre src bsp http inf for ima
原文地址:https://www.cnblogs.com/ocpc/p/12823123.html