Number of Ways to Buy Pens and Pencils LeetCode solution in Python

1
class Solution:
2
def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:
3
return sum(
4
(total - pens * cost1) // cost2 + 1 for pens in range(total // cost1 + 1)
5
)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0