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}); + } +}