Skip to content

Commit 1c83c79

Browse files
committed
Add 1015
1 parent f296287 commit 1c83c79

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
| 994 | Rotting Oranges | Medium | O(N^2) | O(N) | Trees, Recursion | | |
193193
| 1004 | Max Consecutive Ones III | Medium | O(N) | O(1) | Sliding Window, Two Pointers | | |
194194
| 1007 | Minimum Domino Rotations For Equal Row | Medium | O(N) | O(1) | Array, Greedy | | |
195+
| 1015 | Smallest Integer Divisible by K | Medium | O(K) | O(K) | Math | | |
195196
| 1022 | Sum of Root To Leaf Binary Numbers | Easy | O(N) | O(H) | Tree | | |
196197
| 1026 | Maximum Difference Between Node and Ancestor | Medium | O(N) | O(H) | Tree, DFS | | |
197198
| 1029 | Two City Scheduling | Easy | O(NlogN) | O(N) | Greedy | Good Problem | |
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# @lc app=leetcode id=1015 lang=python3
3+
#
4+
# [1015] Smallest Integer Divisible by K
5+
#
6+
7+
# @lc code=start
8+
# TAGS: Math
9+
# REVIEWME: Math
10+
class Solution:
11+
# 48 ms, 76.4%. Time: O(K). Space: O(K)
12+
def smallestRepunitDivByK(self, K: int) -> int:
13+
visited = set()
14+
cnt = rem = 0
15+
while 1:
16+
cnt += 1
17+
rem = (rem * 10 + 1) % K
18+
if rem in visited: return -1
19+
visited.add(rem)
20+
if rem == 0: return cnt
21+
22+
# @lc code=end
23+

testcases/1015

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
1
2+
2
3+
3
4+
4
5+
5
6+
6
7+
7
8+
8
9+
9
10+
10
11+
11
12+
12
13+
13
14+
14
15+
15
16+
16
17+
17
18+
18
19+
19
20+
20
21+
21
22+
22
23+
23
24+
24
25+
25
26+
26

0 commit comments

Comments
 (0)