149

来源:互联网 发布:正规java培训班 编辑:程序博客网 时间:2024/06/05 17:09

5.22

public class Solution {    /**     * @param prices: Given an integer array     * @return: Maximum profit     */    public int maxProfit(int[] prices) {        // write your code here        int max = 0;        int length = prices.length;        if(length <= 1){            return 0;        }        for(int i = 0;i < length -1;i++){            for(int j = i+1;j < length;j++){                int tmp = prices[j] - prices[i];                if(tmp > max){                    max = tmp;                }                //System.out.println(i +"," + j + ",tmp:" + tmp);            }        }        return max;    }}


原创粉丝点击