Advertisement
STANAANDREY

maxProfit

Apr 6th, 2020
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.28 KB | None | 0 0
  1. class Solution {
  2.     public int maxProfit(int[] prices) {
  3.         int maxprofit = 0;
  4.         for (int i = 1; i < prices.length; i++) {
  5.             if (prices[i] > prices[i - 1])
  6.                 maxprofit += prices[i] - prices[i - 1];
  7.         }
  8.         return maxprofit;
  9.     }
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement