MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / maxProfit

Method maxProfit

src/com/blankj/easy/_0122/Solution.java:13–19  ·  view source on GitHub ↗
(int[] prices)

Source from the content-addressed store, hash-verified

11 */
12public class Solution {
13 public int maxProfit(int[] prices) {
14 int max = 0;
15 for (int i = 1; i < prices.length; ++i) {
16 if (prices[i] > prices[i - 1]) max += prices[i] - prices[i - 1];
17 }
18 return max;
19 }
20
21 public static void main(String[] args) {
22 Solution solution = new Solution();

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected