码迷,mamicode.com
首页 > 其他好文 > 详细

买卖股票的最佳时机

时间:2017-03-09 00:28:53      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:for   int   ret   fit   max   math   return   array   imu   

public class Solution {
/**
* @param prices: Given an integer array
* @return: Maximum profit
*/
public int maxProfit(int[] prices) {
// write your code here
int Max = 0;
if( prices == null || prices.length == 0)
return 0;

for(int i = 0;i< prices.length ;i++){
for(int j = i;j< prices.length ;j++)
Max = Math.max(Max, prices[j] - prices[i]);
}
return Max;
}
}

买卖股票的最佳时机

标签:for   int   ret   fit   max   math   return   array   imu   

原文地址:http://www.cnblogs.com/yiwenhao/p/6523517.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!