当前位置:网站首页>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;
// }
// }边栏推荐
- npm install失败
- gin的中间件和路由分组
- 陈强教授《机器学习及R应用》课程 第十四章作业
- 电脑重装系统后桌面图标如何调小尺寸
- Jenkins API groovy calling practice: Jenkins Core Api & Job DSL to create a project
- The sword refers to the offer, cuts the rope 2
- 陈强教授《机器学习及R应用》课程 第十五章作业
- 昇腾AI开发者创享日南京站!一起CANN机器狗+AI机械臂实现硬核智慧救援!燃爆现场~
- Sandbox中的进程/线程相关-2
- 七夕力扣刷不停,343. 整数拆分(剑指 Offer 14- I. 剪绳子、剑指 Offer 14- II. 剪绳子 II)
猜你喜欢

Ledong Fire Rescue Brigade was invited to carry out fire safety training for cadres

FFmpeg multimedia file processing (implementation of ffmpeg operation directory and list)

Explanation of RTSP protocol

5G China unicom AP:B SMS ASCII Transcoding Requirements

RTSP协议讲解

FPGA中串口通信的时钟频率和波特率计数

Unity3d_API_GPS_LocationService

乐东消防救援大队应邀为干部开展消防安全培训

现在40系显卡都快出来了,为何1060型号的显卡还有这么多人用?

阿里大淘系模型治理阶段性分享
随机推荐
FFmpeg multimedia file processing (ffmpeg prints audio and video Meta information)
5G China unicom AP:B SMS ASCII Transcoding Requirements
Q_04_06 把它放在一起:传送
[MRCTF2020]套娃-1
The sword refers to the offer, cuts the rope 2
为什么文字不贴合边
Periodic sharing of Alibaba Da Tao system model governance
技嘉显卡 RGBFusion 不能调光解决方法
Professor Chen Qiang's "Machine Learning and R Application" course Chapter 13 Assignment
昇腾AI开发者创享日南京站!一起CANN机器狗+AI机械臂实现硬核智慧救援!燃爆现场~
陈强教授《机器学习及R应用》课程 第十三章作业
Time series analysis course lab report
力扣解法汇总1413-逐步求和得到正数的最小值
Sandbox中的进程/线程相关-2
陈强教授《机器学习及R应用》课程 第十四章作业
NFS 特别注意权限的问题
[极客大挑战 2019]Upload
FFmpeg多媒体文件处理(ffmpeg操作目录及list的实现)
Q_04_07 进一步探索
glibc memory management model freeing C library memory cache