Skip to content

Commit 65f6019

Browse files
committed
Create 2240.number-of-ways-to-buy-pens-and-pencils.py
1 parent 1b24aae commit 65f6019

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# https://leetcode.cn/problems/number-of-ways-to-buy-pens-and-pencils
2+
3+
4+
class Solution1:
5+
'''
6+
Date: 2023.09.01
7+
Pass/Error/Bug: 1/2/0
8+
执行用时: 380 ms, 在所有 Python3 提交中击败了 78.99% 的用户
9+
内存消耗:15.72 MB, 在所有 Python3 提交中击败了 34.06% 的用户
10+
'''
11+
def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:
12+
cost_min = min(cost1, cost2)
13+
cost_max = max(cost1, cost2)
14+
15+
n_res = 0
16+
for i in range(total // cost_max + 1):
17+
n_res += (total - i * cost_max) // cost_min + 1
18+
19+
return n_res

0 commit comments

Comments
 (0)