当前位置:网站首页>NC7 买卖股票的最好时机(一)
NC7 买卖股票的最好时机(一)
2022-08-09 13:02:00 【syc596】
NC7 买卖股票的最好时机(一)
买卖股票的最好时机(一)_牛客题霸_牛客网 (nowcoder.com)
//11
//贪心
import java.util.*;
public class Solution {
public int maxProfit (int[] prices) {
int maxProfit=0;
int minPrice=prices[0];
for(int i=1;i<prices.length;i++){
minPrice=Math.min(minPrice,prices[i]);
maxProfit=Math.max(maxProfit,prices[i]-minPrice);
}
return maxProfit;
}
}
// //动规
// import java.util.*;
// public class Solution {
// public int maxProfit (int[] prices) {
// int min=prices[0];
// int[] dp=new int[prices.length+1];
// dp[0]=0;
// int ret=0;
// for(int i=1;i<prices.length;i++){
// if(prices[i]<min){
// min=prices[i];
// }
// dp[i]=prices[i]-min;
// ret=Math.max(ret,dp[i]);
// }
// return ret;
// }
// }
边栏推荐
- 关于做2D游戏时,Canvas边界显示在Game窗口的问题
- Anta and Huawei Sports Health jointly verify the champion running shoes and lead Chinese sports with innovation
- 安踏携手华为运动健康共同验证冠军跑鞋 创新引领中国体育
- 时间序列分析课程实验报告
- Dry+Bean+Dataset R语言数据分析,报告英文
- 剑指 Offer 57 - II. 和为s的连续正数序列(滑动窗口)
- Sandbox中的进程/线程相关-1
- CPU-MIPS32 instruction architecture (unlocked pipeline microprocessor)
- 剑指 Offer 43. 1~n 整数中 1 出现的次数(递归、数学)
- Jenkins API groovy calling practice: Jenkins Core Api & Job DSL to create a project
猜你喜欢
19、学习MySQL 索引
Unity3d_API_GPS_LocationService
WSA工具箱安装应用商店提示无法工作怎么解决?
GIN file upload and return
Anta and Huawei Sports Health jointly verify the champion running shoes and lead Chinese sports with innovation
gin's middleware and routing grouping
FFmpeg multimedia file processing (implementation of ffmpeg operation directory and list)
jenkins api创建自定义pipeline
乐东消防救援大队应邀为干部开展消防安全培训
5G China unicom AP:B SMS ASCII Transcoding Requirements
随机推荐
Explanation of RTSP protocol
陈强教授《机器学习及R应用》课程 第十七章作业
puzzle(016.5)逻辑电路
FPGA-在ISE中错误总结(更新中)
七夕力扣刷不停,343. 整数拆分(剑指 Offer 14- I. 剪绳子、剑指 Offer 14- II. 剪绳子 II)
行程和用户[阅读理解法]
GIN a preliminary study, the environment is installed
Professor Chen Qiang the machine learning and R application course chapter 18 assignments
Anta and Huawei Sports Health jointly verify the champion running shoes and lead Chinese sports with innovation
【NVIDIA】Tesla V100安装NVIDIA-Driver驱动程序适配CUDA-Toolkit-11.6
Draw a histogram with plot_hist_numeric()
IDEA Gradle 常遇问题(二)(持续更新)
剑指 Offer 56 - II. 数组中数字出现的次数 II(位运算)
LeetCode 37. Solve Sudoku
RTSP协议讲解
Yocto 可以下载的第三方库
R语言kaggle 游戏数据探索与可视化
5G 联通网管设计思路
ARM board adds routing function
[FPGA Tutorial Case 48] Image Case 8 - Realization of Converting RGB Image to HSV Image Based on FPGA, Assisted Verification by MATLAB