aboutsummaryrefslogtreecommitdiff
path: root/count_ints_even_sum.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'count_ints_even_sum.cpp')
-rw-r--r--count_ints_even_sum.cpp26
1 files changed, 0 insertions, 26 deletions
diff --git a/count_ints_even_sum.cpp b/count_ints_even_sum.cpp
deleted file mode 100644
index 83070c6..0000000
--- a/count_ints_even_sum.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-// 2180. Count Integers With Even Digit Sum
-#include "leetcode.h"
-
-/*
- * given a positive integer 'num', return the number of positive integersless
- * than or equal to 'num' whose digit sums are event. the digitsum of a positive
- * integer is the sum of all of its digits.
- */
-
-class Solution {
-public:
- int countEven(int num) {
- int tmp = num, sum = 0;
- while (num > 0) {
- sum += num % 10;
- num /= 10;
- }
- return sum % 2 == 0 ? tmp / 2 : (tmp - 1) / 2;
- }
-};
-
-int main() {
- Solution obj;
- printf("%d\n", obj.countEven(4)); // expect: 2
- printf("%d\n", obj.countEven(30)); // expect: 14
-}