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

Class Solution

src/com/blankj/easy/_0122/Solution.java:12–26  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2017/10/11 desc :

Source from the content-addressed store, hash-verified

10 * </pre>
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();
23 System.out.println(solution.maxProfit(new int[]{7, 1, 5, 3, 6, 4}));
24 System.out.println(solution.maxProfit(new int[]{7, 6, 4, 3, 1}));
25 }
26}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected