File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
8
8
9
9
| # | Title | Solutions | Video | Difficulty | Tag
10
10
|-----|----------------|---------------|--------|-------------|-------------
11
+ | 2034| [ Stock Price Fluctuation] ( https://leetcode.com/problems/stock-price-fluctuation/ ) | [ Java] ( ../master/src/main/java/com/fishercoder/solutions/_2034.java ) || Medium||
11
12
| 2033| [ Minimum Operations to Make a Uni-Value Grid] ( https://leetcode.com/problems/minimum-operations-to-make-a-uni-value-grid/ ) | [ Java] ( ../master/src/main/java/com/fishercoder/solutions/_2033.java ) || Medium||
12
13
| 2032| [ Two Out of Three] ( https://leetcode.com/problems/two-out-of-three/ ) | [ Java] ( ../master/src/main/java/com/fishercoder/solutions/_2032.java ) || Easy||
13
14
| 2028| [ Find Missing Observations] ( https://leetcode.com/problems/find-missing-observations/ ) | [ Java] ( ../master/src/main/java/com/fishercoder/solutions/_2028.java ) || Medium||
Original file line number Diff line number Diff line change
1
+ package com .fishercoder .solutions ;
2
+
3
+ import java .util .HashMap ;
4
+ import java .util .Map ;
5
+ import java .util .TreeSet ;
6
+
7
+ public class _2034 {
8
+ public static class Solution1 {
9
+ class StockPrice {
10
+ TreeSet <Integer > treeSet ;
11
+ Map <Integer , Integer > map ;
12
+ Map <Integer , Integer > countMap ;
13
+ int current ;
14
+
15
+ public StockPrice () {
16
+ treeSet = new TreeSet <>();
17
+ map = new HashMap <>();
18
+ countMap = new HashMap <>();
19
+ current = 0 ;
20
+ }
21
+
22
+ public void update (int timestamp , int price ) {
23
+ if (map .containsKey (timestamp )) {
24
+ int previousPrice = map .get (timestamp );
25
+ countMap .put (previousPrice , countMap .getOrDefault (previousPrice , 0 ) - 1 );
26
+ if (countMap .get (previousPrice ) <= 0 ) {
27
+ countMap .remove (previousPrice );
28
+ treeSet .remove (previousPrice );
29
+ }
30
+ }
31
+ map .put (timestamp , price );
32
+ treeSet .add (price );
33
+ countMap .put (price , countMap .getOrDefault (price , 0 ) + 1 );
34
+ if (current < timestamp ) {
35
+ current = timestamp ;
36
+ }
37
+ }
38
+
39
+ public int current () {
40
+ return map .get (current );
41
+ }
42
+
43
+ public int maximum () {
44
+ return treeSet .last ();
45
+ }
46
+
47
+ public int minimum () {
48
+ return treeSet .first ();
49
+ }
50
+ }
51
+ }
52
+ }
You can’t perform that action at this time.
0 commit comments