122. Best Time to Buy and Sell Stock II
来源:互联网 发布:光盘刻录软件nero 编辑:程序博客网 时间:2024/06/05 15:50
大概意思是不是只找最大差值,而是把所有的差值全部找出来
网上某个大佬提供了一个很巧妙的思路,就是把后一个减去前一个,然后得到差值如果大于零就加上去
int maxProfit(int* prices, int pricesSize)
{
int i=1,profit=0;
for(;i<pricesSize;i++)
{
if(prices[i]-prices[i-1]>0)
profit=profit+prices[i]-prices[i-1];
}
return profit;
}
阅读全文
0 0
- 122. Best Time to Buy and Sell Stock II
- LeetCode 122. Best Time to Buy and Sell Stock II
- 122.Best Time to Buy and Sell Stock II
- [Leetcode] 122. Best Time to Buy and Sell Stock II
- [leetcode] 122.Best Time to Buy and Sell Stock II
- 【leetcode】122.Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II
- 【LeetCode】122.Best Time to Buy and Sell Stock II
- [leetcode] 122. Best Time to Buy and Sell Stock II
- LeetCode #122. Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II LeetCode
- 122. Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II
- [LeetCode]122. Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II
- Leetcode 122. Best Time to Buy and Sell Stock II
- leetcode 122. Best Time to Buy and Sell Stock II
- js取得gridview中获取checkbox选中的值
- Android_网络协议--okHttp
- 机器学习
- java泛型指导手册(part1)
- Java static 关键字详解
- 122. Best Time to Buy and Sell Stock II
- APK瘦身最佳实践(Google I/O '17)
- cogs755 山海经
- FreeBSD内核模块开发入门
- tput先对应的用法
- Spring Boot的应用正常启动与关闭
- android 线程池源码解析
- MFC下应用opencv(1):显示图片
- 05 TI ZStack协议栈的分层及设备分类