Skip to content

Commit 2ef0d25

Browse files
committed
Added 2180
1 parent 25271be commit 2ef0d25

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@
651651
| 2140 | [Solving Questions With Brainpower](src/2140.solving-questions-with-brainpower.py) | Medium | O(N) | O(N) | Array, Dynamic Programming | | |
652652
| 2176 | [Count Equal and Divisible Pairs in an Array](src/2176.count-equal-and-divisible-pairs-in-an-array.py) | Easy | O(N^2) | O(1) | Array | | |
653653
| 2177 | [Count Equal and Divisible Pairs in an Array](src/2177.find-three-consecutive-integers-that-sum-to-a-given-number.py) | Medium | O(1) | O(1) | Math, Binary Search | | |
654+
| 2180 | [Count Integers With Even Digit Sum](src/2180.count-integers-with-even-digit-sum.py) | Easy | O(1) | O(1) | Math, Simulation | | |
654655
| 2185 | [Counting Words With a Given Prefix](src/2185.counting-words-with-a-given-prefix.py) | Easy | O(N) | O(1) | Array, String | | |
655656
| 2186 | [Minimum Number of Steps to Make Two Strings Anagram II](src/2186.minimum-number-of-steps-to-make-two-strings-anagram-ii.py) | Medium | O(N) | O(N) | Hash Table, String, Counting | | |
656657
| 2190 | [Most Frequent Number Following Key In an Array](src/2190.most-frequent-number-following-key-in-an-array.py) | Easy | O(N) | O(N) | Array, Hash Table, Counting | | |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# @lc app=leetcode id=2180 lang=python3
3+
#
4+
# [2180] Count Integers With Even Digit Sum
5+
#
6+
7+
# @lc code=start
8+
# TAGS: Math, Simulation
9+
class Solution:
10+
def countEven(self, num: int) -> int:
11+
cnt = 0
12+
for i in range(1, num + 1):
13+
cnt += sum(int(c) for c in str(i)) % 2 == 0
14+
return cnt
15+
16+
# Math
17+
# For a num with even sum of its digits, count of Integers With Even Digit Sum less than or equal to num is num/2
18+
# For a num with odd sum of its digits, count of Integers With Even Digit Sum less than or equal to num is (num-1)/2
19+
# Time and Space: O(1)
20+
def countEven1(self, num: int) -> int:
21+
if sum(int(c) for c in str(num)) % 2:
22+
return (num - 1) // 2
23+
return num // 2
24+
25+
# @lc code=end

0 commit comments

Comments
 (0)