Skip to content

Commit c1ffa29

Browse files
adam.linadam.lin
adam.lin
authored and
adam.lin
committed
countSymmetricIntegers
1 parent 6ab31cd commit c1ffa29

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

.vscode/settings.json

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"files.associations": {
3+
"list": "cpp",
4+
"algorithm": "cpp",
5+
"atomic": "cpp",
6+
"bit": "cpp",
7+
"cctype": "cpp",
8+
"charconv": "cpp",
9+
"clocale": "cpp",
10+
"cmath": "cpp",
11+
"compare": "cpp",
12+
"concepts": "cpp",
13+
"cstddef": "cpp",
14+
"cstdint": "cpp",
15+
"cstdio": "cpp",
16+
"cstdlib": "cpp",
17+
"cstring": "cpp",
18+
"ctime": "cpp",
19+
"cwchar": "cpp",
20+
"exception": "cpp",
21+
"string": "cpp",
22+
"vector": "cpp",
23+
"format": "cpp",
24+
"initializer_list": "cpp",
25+
"ios": "cpp",
26+
"iosfwd": "cpp",
27+
"iostream": "cpp",
28+
"istream": "cpp",
29+
"iterator": "cpp",
30+
"limits": "cpp",
31+
"locale": "cpp",
32+
"memory": "cpp",
33+
"new": "cpp",
34+
"optional": "cpp",
35+
"ostream": "cpp",
36+
"sstream": "cpp",
37+
"stdexcept": "cpp",
38+
"streambuf": "cpp",
39+
"system_error": "cpp",
40+
"tuple": "cpp",
41+
"type_traits": "cpp",
42+
"typeinfo": "cpp",
43+
"utility": "cpp",
44+
"xfacet": "cpp",
45+
"xiosbase": "cpp",
46+
"xlocale": "cpp",
47+
"xlocbuf": "cpp",
48+
"xlocinfo": "cpp",
49+
"xlocmes": "cpp",
50+
"xlocmon": "cpp",
51+
"xlocnum": "cpp",
52+
"xloctime": "cpp",
53+
"xmemory": "cpp",
54+
"xstring": "cpp",
55+
"xtr1common": "cpp",
56+
"xutility": "cpp"
57+
}
58+
}

2843_countSymmetricIntegers.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <list>
4+
using namespace std;
5+
6+
class Solution {
7+
public:
8+
int countSymmetricIntegers(int low, int high) {
9+
list<int> container;
10+
int left;
11+
int right;
12+
13+
for (int i = low; i <= high; i++) {
14+
left = 0;
15+
right = 0;
16+
string s = to_string(i);
17+
int size = s.size();
18+
int index = size / 2;
19+
20+
if (size % 2 != 0)
21+
continue;
22+
23+
for (int a = 0; a < size; ++a) {
24+
if (a < index)
25+
left += stoi(string(1, s[a]));
26+
else
27+
right += stoi(string(1, s[a]));
28+
}
29+
30+
if (left == right) {
31+
container.push_back(i);
32+
}
33+
}
34+
return container.size();
35+
}
36+
};
37+

0 commit comments

Comments
 (0)