File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ public class LeetCode_169_044 {
2
+ public int majorityElement (int [] nums ) {
3
+ return divc (nums , 0 , nums .length - 1 );
4
+ }
5
+ private int divc (int [] nums , int l , int r ){
6
+ if (l == r )
7
+ return nums [l ];
8
+ int mid = l + (r - l )/2 ;
9
+ int ls = divc (nums , l , mid );
10
+ int rs = divc (nums , mid +1 , r );
11
+ if (ls == rs )
12
+ return ls ;
13
+ int c1 = 0 , c2 = 0 ;
14
+ for (int i = l ; i <= r ; i ++){
15
+ if (nums [i ] == ls ) c1 ++;
16
+ if (nums [i ] == rs ) c2 ++;
17
+ }
18
+ return c1 > c2 ? ls : rs ;
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ class LeetCode_746_044 {
2
+ public int minCostClimbingStairs (int [] cost ) {
3
+ int step [] = new int [1024 ];
4
+ step [0 ] = 0 ;
5
+ step [1 ] = 0 ;
6
+ if (cost .length == 0 ) {
7
+ return 0 ;
8
+ }
9
+ if (cost .length == 1 ) {
10
+ return cost [0 ];
11
+ }
12
+ if (cost .length == 2 ) {
13
+ return Math .min (cost [0 ], cost [1 ]);
14
+ }
15
+ for (int i = 2 ; i <= cost .length ; i ++) {
16
+ step [i ] = Math .min (step [i - 1 ] + cost [i - 1 ], step [i - 2 ] + cost [i - 2 ]);
17
+ }
18
+ return step [cost .length ];
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments