题目链接:https://www.lintcode.com/problem/best-time-to-buy-and-sell-stock-ii/description
/**
* @param prices: Given an integer array
* @return: Maximum profit
*/
func maxProfit (prices []int) int {
// write your code here
var profit int = 0;
var i int = 0;
for i = 1; i < len(prices); i++ {
var diff int = prices[i] - prices[i - 1];
if (diff > 0) {
profit += diff;
}
}
return profit;
}
func main() {
var prices []int = []int{2,1,2,0,1};
var profit int = maxProfit(prices);
fmt.Println(profit);
}