国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

LEETCODE--Add Strings

2019-11-10 17:21:43
字體:
供稿:網(wǎng)友

Given two non-negative integers num1 and num2 rePResented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is < 5100. Both num1 and num2 contains only digits 0-9. Both num1 and num2 does not contain any leading zero. You must not use any built-in BigInteger library or convert the inputs to integer directly.

class Solution {public: string addStrings(string num1, string num2) { int i = num1.length() - 1; int j = num2.length() - 1; string str; int carry = 0; while( i >= 0 || j >= 0 || carry){ int sum = 0; if( i >= 0) sum += num1[i--] - '0'; if( j >= 0) sum += num2[j--] - '0'; sum += carry; carry = sum / 10; sum %= 10; str += to_string(sum); } reverse(str.begin(), str.end()); return str; }};
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 山丹县| 都江堰市| 大新县| 固始县| 来宾市| 察哈| 尼木县| 石柱| 灵丘县| 民丰县| 蓝田县| 左贡县| 涡阳县| 嘉定区| 太湖县| 永丰县| 响水县| 平定县| 龙里县| 永安市| 金川县| 沈阳市| 和硕县| 甘谷县| 五常市| 水城县| 攀枝花市| 双鸭山市| 汝州市| 蒙自县| 砀山县| 辽中县| 民勤县| 赤城县| 时尚| 凯里市| 湘乡市| 墨玉县| 巴彦淖尔市| 奉节县| 佛学|