LeetCode solutions

2756. Buy Two Chocolates

My accepted Python solution to LeetCode problem 2756, Buy Two Chocolates, running in 2ms.

  • Difficulty: Easy
  • Python
  • Runtime 2ms
  • Memory 17.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 2ms, memory 17.2MB, accepted 2025-12-30.

python
class Solution:
    def buyChoco(self, prices: List[int], money: int) -> int:
        prices.sort()
        min_cost = prices[0] + prices[1]
        if min_cost <= money:
            return money - min_cost
        return money

Source