File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
best-time-to-buy-and-sell-stock Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public int maxProfit (int [] prices ) {
3
+ int price = prices [0 ];
4
+ int maxProfit = 0 ;
5
+
6
+ for (int i =1 ; i <prices .length ; i ++){
7
+ int profit = prices [i ]-price ;
8
+ maxProfit = Math .max (maxProfit , profit );
9
+ price = Math .min (price , prices [i ]);
10
+ }
11
+ return maxProfit ;
12
+ }
13
+ }
14
+
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public List <List <String >> groupAnagrams (String [] strs ) {
3
+ HashMap <String , List <String >> map = new HashMap <>();
4
+
5
+ for (String s : strs ) {
6
+ char [] c = s .toCharArray ();
7
+ Arrays .sort (c );
8
+
9
+ String key = new String (c );
10
+ if (!map .containsKey (key )) {
11
+ map .put (key , new ArrayList <>());
12
+ }
13
+
14
+ map .get (key ).add (s );
15
+ }
16
+ return new ArrayList <>(map .values ());
17
+ }
18
+ }
19
+
20
+
You can’t perform that action at this time.
0 commit comments