题解 | #买卖股票的最好时机(一)#
买卖股票的最好时机(一)
https://www.nowcoder.com/practice/64b4262d4e6d4f6181cd45446a5821ec
import java.util.*;
public class Solution {
public int maxProfit (int[] prices) {
// 只进行一次买入和卖出
int ret =0;
//双层遍历
int n = prices.length;
for(int i=0;i<n;i++){
for(int j=i;j <n;j++){
ret = Math.max(ret,prices[j]-prices[i]);
}
}
return ret;
}
}


vivo公司福利 364人发布