Skip to content

Commit 946194c

Browse files
authored
第四周作业
1 parent f80f8e0 commit 946194c

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int majorityElement(int[] nums) {
3+
Map<Integer,Integer> map = new HashMap<>();
4+
for(int num:nums){
5+
map.put(num,map.getOrDefault(num,0)+1);
6+
}
7+
Integer numsD = nums.length/2;
8+
// BigDecimal nums2 = new BigDecimal(numsD);
9+
for(Integer key:map.keySet()){
10+
if(map.get(key) > numsD ){
11+
return key;
12+
}
13+
}
14+
return 0;
15+
}
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int minCostClimbingStairs(int[] cost) {
3+
int len = cost.length;
4+
int[] dp = new int[len];
5+
dp[0] = cost[0];
6+
dp[1] = cost[1];
7+
for (int i = 2; i < len; i++) {
8+
dp[i] = Math.min(dp[i-1],dp[i-2]) + cost[i];
9+
}
10+
return Math.min(dp[len-1],dp[len-2]);
11+
}
12+
}

0 commit comments

Comments
 (0)