Skip to content

Commit 5b817ab

Browse files
committed
LeetCode 2481. Minimum Cuts to Divide a Circle
1 parent 8b331fa commit 5b817ab

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ Solutions to LeetCode problems. The first column links to the problem in LeetCod
350350
| [2115. Find All Possible Recipes from Given Supplies][lc2115] | 🟠 Medium | [![python](res/py.png)][lc2115py] |
351351
| [2131. Longest Palindrome by Concatenating Two Letter Words][lc2131] | 🟠 Medium | [![python](res/py.png)][lc2131py] |
352352
| [2136. Earliest Possible Day of Full Bloom][lc2136] | 🔴 Hard | [![python](res/py.png)][lc2136py] |
353+
| [2481. Minimum Cuts to Divide a Circle][lc2481] | 🟢 Easy | [![python](res/py.png)][lc2481py] |
353354

354355
[🔝 Back to Top 🔝](#coding-challenges)
355356

@@ -1024,6 +1025,8 @@ Solutions to LeetCode problems. The first column links to the problem in LeetCod
10241025
[lc2131py]: leetcode/longest-palindrome-by-concatenating-two-letter-words.py
10251026
[lc2136]: https://leetcode.com/problems/earliest-possible-day-of-full-bloom/
10261027
[lc2136py]: leetcode/earliest-possible-day-of-full-bloom.py
1028+
[lc2481]: https://leetcode.com/problems/minimum-cuts-to-divide-a-circle/
1029+
[lc2481py]: leetcode/minimum-cuts-to-divide-a-circle.py
10271030

10281031
## CodeWars problems
10291032

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# 2481. Minimum Cuts to Divide a Circle
2+
# 🟢 Easy
3+
#
4+
# https://leetcode.com/problems/minimum-cuts-to-divide-a-circle/
5+
#
6+
# Tags: Math - Geometry
7+
8+
import timeit
9+
10+
11+
# If n == 1, we do not need to cut, otherwise, if the number is uneven
12+
# we need to make n radial cuts, but if n is uneven, we can make edge
13+
# to edge cuts, diametral, and we only need n // 2 of them.
14+
#
15+
# Time complexity: O(1)
16+
# Space complexity: O(1)
17+
#
18+
# Runtime: 59 ms, faster than 40.00%
19+
# Memory Usage: 13.9 MB, less than 20.00%
20+
class Solution:
21+
def numberOfCuts(self, n: int) -> int:
22+
if n % 2:
23+
return n if n != 1 else 0
24+
return n // 2
25+
26+
27+
def test():
28+
executors = [Solution]
29+
tests = [
30+
[1, 0],
31+
[3, 3],
32+
[4, 2],
33+
]
34+
for executor in executors:
35+
start = timeit.default_timer()
36+
for _ in range(1):
37+
for col, t in enumerate(tests):
38+
sol = executor()
39+
result = sol.numberOfCuts(t[0])
40+
exp = t[1]
41+
assert result == exp, (
42+
f"\033[93m» {result} <> {exp}\033[91m for"
43+
+ f" test {col} using \033[1m{executor.__name__}"
44+
)
45+
stop = timeit.default_timer()
46+
used = str(round(stop - start, 5))
47+
cols = "{0:20}{1:10}{2:10}"
48+
res = cols.format(executor.__name__, used, "seconds")
49+
print(f"\033[92m» {res}\033[0m")
50+
51+
52+
test()

0 commit comments

Comments
 (0)