Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit eb9cf15

Browse files
solved leetcode daily challenge, add strings
1 parent e41e4e3 commit eb9cf15

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

‎LeetCode/Add_Strings/main.cxx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <bits/stdc++.h>
2+
#include <gtest/gtest.h>
3+
using namespace std;
4+
5+
6+
//// START
7+
/*
8+
## Add Strings
9+
10+
*/
11+
12+
13+
class Solution {
14+
public:
15+
string addStrings(string num1, string num2) {
16+
int c = 0;
17+
if (num1.size() < num2.size())swap(num1, num2);
18+
string ret;
19+
for (int i = 0; i < num1.size(); i++) {
20+
int sum = 0;
21+
sum += num1[num1.size() - 1 - i]-'0';
22+
if (i < num2.size()) {
23+
sum += num2[num2.size() - 1 - i]-'0';
24+
}
25+
sum += c;
26+
if (sum >= 10) {
27+
c = 1;
28+
} else {
29+
c = 0;
30+
}
31+
sum %= 10;
32+
ret.push_back(char('0' + sum));
33+
}
34+
if (c != 0) {
35+
ret.push_back('1');
36+
}
37+
reverse(ret.begin(), ret.end());
38+
return ret;
39+
}
40+
};
41+
42+
//// END
43+
struct T {
44+
45+
};
46+
47+
TEST(Solution, test) {
48+
T ts[] = {
49+
{
50+
51+
},
52+
{
53+
54+
},
55+
56+
};
57+
58+
for (T t : ts) {
59+
Solution solution;
60+
61+
}
62+
}
63+
64+
int main() {
65+
testing::InitGoogleTest();
66+
67+
return RUN_ALL_TESTS();
68+
}
69+
70+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /