We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a74a76b commit 5f1b238Copy full SHA for 5f1b238
C++/count-integers-with-even-digit-sum.cpp
@@ -0,0 +1,38 @@
1
+// Time: O(logn)
2
+// Space: O(1)
3
+
4
+// math
5
+class Solution {
6
+public:
7
+ int countEven(int num) {
8
+ const auto& parity = [](int x) {
9
+ int result = 0;
10
+ for (; x; x /= 10) {
11
+ result += x % 10;
12
+ }
13
+ return result % 2;
14
+ };
15
+ return (num - parity(num)) / 2;
16
17
+};
18
19
20
21
22
+class Solution2 {
23
24
25
26
27
28
29
30
31
32
33
+ for (int i = 1; i <= num; ++i) {
34
+ result += static_cast<int>(parity(i) == 0);
35
36
+ return result;
37
38
0 commit comments