1 string addStrings(string num1, string num2) { 2 if( num1.empty() ) return num2; 3 if( num2.empty() ) return num1; 4 5 string::reverse_iterator it1 = num1.rbegin() ; 6 string::reverse_iterator it2 = num2.rbegin() ; 7 string s ; 8 int up = 0; 9 while( it1 !
publicclassSolution {publicString addStrings(String num1, String num2) {if(num1 ==null|| num2 ==null) {returnnull; }intsum = 0; StringBuilder str=newStringBuilder();for(inti = num1.length() - 1, j = num2.length() - 1; i >= 0 || j >= 0; i--, j--) {intx = i < ...
You must not use any built-in BigInteger library or convert the inputs to integer directly. 由于是参加LeetCode的Weekly Contest,水平不够,在线编的代码比较差(哈哈,忍忍吧~~)。0~9的ASCII码是48~57,并且我们是对单独每一位做加法运算,所以,对两个字符求和转换成数字时直接取余“%96”,对一个字符转换...
[LeetCode] Add Stringsxiaoli7 华中科技大学 工学硕士1 人赞同了该文章 Description Add Strings: Given two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string. Example: Input: num1 = "456", num2 = "77" Output: "533" Solution...
leetcode 415. Add Strings Given two non-negative integersnum1andnum2represented as string, return the sum ofnum1andnum2. Note: The length of bothnum1andnum2is < 5100. Bothnum1andnum2contains only digits0-9. Bothnum1andnum2does not contain any leading zero....
【Leetcode】Add Strings Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. 1 注意题中num1和num2是以string形式储存的,所以在做运算的时候需要转换成ASCII,用ord()函数 2 题中num1和num2以string形式存储,若不能用build-in函数,则需要先把string...
https://leetcode-cn.com/problems/add-strings/ 解法 解法1:我的解法 class Solution{public:stringaddStrings(string num1,string num2){string res;inti=num1.size()-1;intj=num2.size()-1;intcarry=0;for(;i>=0&&j>=0;i--,j--){intsum=(num1[i]-'0')+(num2[j]-'0')+carry;intval=...
使用carry_over. 这种类型的题在 LeetCode 中出现过很多次, 总会以不同的面目出现, 比如链表啥的. 代码解读 classSolution{ public: stringaddStrings(stringnum1,stringnum2) { intcarry_over=0; inti=num1.size()-1,j=num2.size()-1; ...
[LeetCode] 1221. Split a String in Balanced Strings 2019-12-21 02:54 −Balanced strings are those who have equal quantity of 'L' and 'R' characters. Given a balanced string s split it in the maximum amount... Zhentiw 0 3
LeetCode 67. Add Binary 程序员木子 香港浸会大学 数据分析与人工智能硕士在读Description Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0. Example 1: Input: a = "11", b = "1"Output: ...