Skip to content

Commit 3496de4

Browse files
committed
Time: 0 ms (100%), Space: 6.5 MB (17.22%) - LeetHub
1 parent 6b88312 commit 3496de4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
int alternateDigitSum(int n) {
4+
string str = to_string(n);
5+
int sum = 0;
6+
int toogle = -1;
7+
for (auto& i: str) {
8+
sum += (i - '0') * -1 * toogle;
9+
toogle *= -1;
10+
}
11+
return sum;
12+
13+
}
14+
};

0 commit comments

Comments
 (0)