Advertisement
gelita

buy and sell stock max profit javascript

Mar 9th, 2020
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.25 KB | None | 0 0
  1. var maxProfit = function(prices) {
  2.     let result = 0;
  3.     let min = prices[0];
  4.     for(let i = 1; i < prices.length; i++) {
  5.         min = Math.min(prices[i], min);
  6.         result = Math.max(result, prices[i] - min);
  7.     }
  8.     return result;
  9. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement