16 lines
360 B
Plaintext
16 lines
360 B
Plaintext
class Solution {
|
|
public int maxProfit(int[] prices) {
|
|
int price = 0;
|
|
for(int i=prices.length-1;i>0;i--){
|
|
for(int j=i-1;j>=0;j--){
|
|
if(prices[i]-prices[j]>price){
|
|
price=prices[i]-prices[j];
|
|
}
|
|
}
|
|
}
|
|
return price;
|
|
}
|
|
}
|
|
//runtime:455 ms
|
|
//memory:41 MB
|