bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 122. Best Time to Buy and Sell Stock II

122. Best Time to Buy and Sell Stock II

Leetcode Solutions

Simple One Pass Approach

  1. Initialize maxProfit to 0.
  2. Loop through the array from the second element to the end.
  3. For each day, check if the price is higher than the previous day.
  4. If it is, add the difference to maxProfit.
  5. Continue to the next day.
  6. Return maxProfit after the loop ends.
UML Thumbnail

Peak Valley Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...