Skip to content

Commit ae5c48d

Browse files
committed
Feb 15
1 parent 9a9d313 commit ae5c48d

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class Solution:
2+
def punishmentNumber(self, n: int) -> int:
3+
4+
def can_partition(s: str, target: int) -> bool:
5+
if not s and target == 0:
6+
return True
7+
if target < 0:
8+
return False
9+
for i in range(len(s)):
10+
left = int(s[:i+1])
11+
right = s[i+1:]
12+
if can_partition(right, target - left):
13+
return True
14+
return False
15+
16+
sum_ = 0
17+
for num in range(1, n+1):
18+
sqr = num * num
19+
if can_partition(str(sqr), num):
20+
sum_ += sqr
21+
return sum_
22+
23+
24+
def main():
25+
n = 10
26+
assert Solution().punishmentNumber(n) == 182
27+
28+
n = 37
29+
assert Solution().punishmentNumber(n) == 1478
30+
31+
32+
if __name__ == '__main__':
33+
main()

2025-02-February-LeetCoding-Challenge/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
| February 11 | [1910. Remove All Occurrences of a Substring](https://leetcode.com/problems/remove-all-occurrences-of-a-substring/) | Medium | Solved |
1818
| February 12 | [2342. Max Sum of a Pair With Equal Sum of Digits](https://leetcode.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/) | Medium | Solved |
1919
| February 13 | [3066. Minimum Operations to Exceed Threshold Value II](https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-ii/) | Medium | Solved |
20-
| February 14 | [1352. Product of the Last K Numbers](https://leetcode.com/problems/product-of-the-last-k-numbers/) | Medium | Unsolved |
21-
| February 15 | []() | | |
20+
| February 14 | [1352. Product of the Last K Numbers](https://leetcode.com/problems/product-of-the-last-k-numbers/) | Medium | Solved |
21+
| February 15 | [2698. Find the Punishment Number of an Integer](https://leetcode.com/problems/find-the-punishment-number-of-an-integer/) | Medium | Solved |
2222
| February 16 | []() | | |
2323
| February 17 | []() | | |
2424
| February 18 | []() | | |
@@ -38,5 +38,5 @@
3838
| Level | Problems | Solved | Unsolved |
3939
| --- | --- | --- | --- |
4040
| Easy | 6 | 6 | 0 |
41-
| Medium | 7 | 6 | 1 |
41+
| Medium | 8 | 8 | 0 |
4242
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)