当前位置:网站首页>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;
// }
// }边栏推荐
- GIN file upload and return
- Explanation of RTSP protocol
- Data Mining-06
- Anta and Huawei Sports Health jointly verify the champion running shoes and lead Chinese sports with innovation
- Unity3d_API_Gyroscope 陀螺仪的接口
- An Offer 21. Adjust the array in order to make odd in even the front (loop invariant)
- Unicom network management protocol block diagram
- 联通网管协议框图
- 陈强教授《机器学习及R应用》课程 第十八章作业
- FFmpeg多媒体文件处理(ffmpeg操作目录及list的实现)
猜你喜欢

GIN a preliminary study, the environment is installed

Unicom network management protocol block diagram

01_iTween_第一天--小球抛物线

uni-app - uview Swiper 轮播图组件点击跳转链接(点击后拿到 item 行数据, 取出数据做操作)

Anta and Huawei Sports Health jointly verify the champion running shoes and lead Chinese sports with innovation

面试攻略系列(二)-- 秒杀系统

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

GIN Bind模式获取参数和表单验证

5G China unicom 直放站 网管协议 实时性要求

FFmpeg multimedia file processing (implementation of ffmpeg operation directory and list)
随机推荐
Q_06_03 表达式
Oracle Recovery Tools修复空闲坏块
The sword refers to Offer 56 - II. Number of occurrences of a number in an array II (bit operation)
FFmpeg multimedia file processing (implementation of ffmpeg operation directory and list)
Yocto 可以下载的第三方库
剑指offer,剪绳子2
GIN Bind模式获取参数和表单验证
JS本地存储 sessionStorage和localStorage
[MRCTF2020]套娃-1
陈强教授《机器学习及R应用》课程 第十五章作业
关于做2D游戏时,Canvas边界显示在Game窗口的问题
Bitmaps and bit operations
Final assignment of R language data analysis in a university
Professor Chen Qiang's "Machine Learning and R Application" course Chapter 16 Assignment
GIN a preliminary study, the environment is installed
蓝桥杯线上模拟赛——Flex 经典骰子布局
LeetCode 37.解数独
puzzle(016.5)逻辑电路
Q_07 词汇表
5G Unicom Network Management Design Ideas