The TransCompilator

Solved LeetCode program · 122 of 1,000

#0122 · Best Time to Buy and Sell Stock II

Medium Array chunk-03.md

Original English source

The prices is a list of 7, 1, 5, 3, 6, and 4. The last is the last position of prices. The profit is 0.
For every spot from 1 to last.
The gain is item spot of prices minus item (spot minus 1) of prices. If gain is more than 0, add gain to profit.

Show profit.

Open in Playground Browse all 1,000 problems

Expected stdout

7