Leetcode Problem 2288. Apply Discount to Prices
2288. Apply Discount to Prices
AI Mock Interview
Leetcode Solutions
Iterate and Replace Prices with Discount
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Split the sentence into words based on spaces.
Iterate through each word in the list of words.
For each word, check if it starts with a dollar sign and is followed by digits only.
If the word represents a price, remove the dollar sign and parse the remaining part as a number.
Apply the discount to the number to get the discounted price.
Format the discounted price to two decimal places and prepend the dollar sign.
Replace the original word with the formatted discounted price.
Join the modified list of words back into a sentence.
Return the modified sentence.
Regex Matching and String Formatting
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...