From 515c15677d9d06d80703a696b4a2b810465c0b73 Mon Sep 17 00:00:00 2001 From: Cool <747682928@qq.com> Date: Sun, 22 Sep 2024 19:41:01 +0800 Subject: [PATCH] =?UTF-8?q?2024/9/22=20LeetCode=20Hot100=20=E6=98=A8?= =?UTF-8?q?=E6=97=A5=E8=B4=AA=E5=BF=83/=E5=8A=A8=E6=80=81=E8=A7=84?= =?UTF-8?q?=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cool/hot100/greedy/Num121.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/com/cool/hot100/greedy/Num121.java diff --git a/src/main/java/com/cool/hot100/greedy/Num121.java b/src/main/java/com/cool/hot100/greedy/Num121.java new file mode 100644 index 0000000..1855f0d --- /dev/null +++ b/src/main/java/com/cool/hot100/greedy/Num121.java @@ -0,0 +1,32 @@ +package com.cool.hot100.greedy; + +import org.junit.Test; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/09/21/23:06 + * DayNumber 3 + * Hard 1 + * Level 3 + */ +public class Num121 { + + public int maxProfit(int[] prices) { + int minPrice=prices[0]; + int maxProfit=0; + for (int i = 1; i < prices.length; i++) { + if(prices[i]maxProfit){ + maxProfit=prices[i]-minPrice; + } + } + return maxProfit; + } + @Test + public void test(){ + maxProfit(new int[]{7,1,5,3,6,4}); + } +}