Algorithms—121.Best Time to Buy and Sell Stock
来源:互联网 发布:简历管理系统 源码 编辑:程序博客网 时间:2024/06/05 11:52
思路:很典型的一题,不细说了
public class Solution { public int maxProfit(int[] prices) {if (prices.length <= 1) {return 0;}int[] change = new int[prices.length - 1];for (int i = 0; i < change.length; i++) {change[i] = prices[i + 1] - prices[i];}int sum = 0;int s = 0;int begin = 0;int end = 0;for (int i = 0; i < change.length; i++) {s += change[i];if (s < 0) {s = 0;begin = i + 1;end = i + 1;}if (change[i] > 0) {end = i;}if (s > sum) {sum = s;}}return sum;}}
0 0
- Algorithms—121.Best Time to Buy and Sell Stock
- 算法设计Week9 LeetCode Algorithms Problem #121. Best Time to Buy and Sell Stock
- Algorithms—122.Best Time to Buy and Sell Stock II
- Algorithms—123.Best Time to Buy and Sell Stock III
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time To Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Unicode字符集下CString与char *转换
- leetcode(2)add two numbers
- 从K近邻算法、距离度量谈到KD树、SIFT+BBF算法
- windows7系统 Internet 信息服务(IIS)管理器 默认网站 右键 没有属性这一项怎么办?
- 集训队分组
- Algorithms—121.Best Time to Buy and Sell Stock
- Android中常见管理者对象的获取
- Algorithms—122.Best Time to Buy and Sell Stock II
- 小插曲:excel的表间数据引用公式vlookup
- 'adb' 不是内部或外部命令,也不是可运行的程序或批处理文件。
- 半夜撸 flap bird
- Leetcode 之 Find Minimum in Rotated Sorted Array
- codeforces 549D D. Haar Features(枚举)
- 【leetcode c++】27 Remove Element