We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parentfa2edc3 commit63a956cCopy full SHA for 63a956c
Easy_415_Add_Strings.js
@@ -0,0 +1,37 @@
1
+/**
2
+ * Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2.
3
+ * Note:
4
+ *
5
+ * The length of both num1 and num2 is < 5100.
6
+ * Both num1 and num2 contains only digits 0-9.
7
+ * Both num1 and num2 does not contain any leading zero.
8
+ * You must not use any built-in BigInteger library or convert the inputs to integer directly.
9
+ */
10
+
11
12
+ *@param {string} num1
13
+ *@param {string} num2
14
+ *@return {string}
15
16
+varaddStrings=function(num1,num2){
17
+varcarry=0;
18
+varlen1=num1.length;
19
+varlen2=num2.length;
20
+varforCount=Math.max(len1,len2);
21
+varnewNum='';
22
+for(vari=0;i<forCount;i++){
23
+vara=parseInt(num1[len1-1-i])||0;
24
+varb=parseInt(num2[len2-1-i])||0;
25
+varc=a+b+carry;
26
+carry=Math.floor(c/10);
27
+vare=c%10;
28
+newNum=e+newNum;
29
+}
30
31
+if(carry){
32
+newNum=carry+newNum
33
34
+returnnewNum;
35
+};
36
37
+console.log(addStrings('12','123')=='135');