暴力法
//c++
class Solution {
public:
int maxProfit(vector<int>& prices)
{
int i, j, max;
max = 0;
for(i = 0; i < prices.size(); i++)
{
for(j = i + 1; j < prices.size(); j++)
{
if(prices[j] - prices[i] > max)
{
max = prices[j] - prices[i];
}
}
}
return max;
}
};
public class Solution {
public int MaxProfit(int[] prices)
{
int i, j, max = 0;
for(i = 0; i < prices.Length - 1; i++)
{
for(j = i + 1; j < prices.Length; j++)
{
if(max < prices[j] - prices[i])
{
max = prices[j] - prices[i];
}
}
}
return max;
}
}