题目描述:力扣

解题思路:

暴力法,两重for循环

class Solution {
    public int maxProfit(int[] prices) {
        int maxprofit = 0;
        for(int i = 0; i < prices.length-1; i++){
            for(int j = i+1; j < prices.length; j++){
                if(prices[j]>prices[i]){
                    maxprofit= Math.max(maxprofit, prices[j]-prices[i]);
                }
            }
        }
        return maxprofit;
    }
}