2288. Apply Discount to Prices

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2288

class Solution:
    def discountPrices(self, sentence: str, discount: int) -> str:
        res = []
        for w in sentence.split():
            if w[0] == '$' and w[1:].isdigit():
                w = f'${int(w[1:]) * (1 - discount / 100):.2f}'
            res.append(w)
        return ' '.join(res)