题目大意:求两个数差值最大

思路:构造一个两数之差的数组,求该数组中子串和最大

[7,1,5,3,6,4]

[-6,4,-2,3,-2]

ans = 5 //4-2+3

import java.util.*;
public class Solution {
    public int maxProfit (int[] prices) {
        // write code here
        int[] num = new int[prices.length - 1];
        int i,ans,temp;
        
        for(i = 0; i < num.length; i++)num[i] = prices[i+1] - prices[i];
        ans = temp = 0;
        
        for(i = 0; i < num.length; i++){
            temp+=num[i];
            ans = Math.max(temp,ans);
            if(temp <= 0)temp=0;
        }
        return ans;
    }
}