8000 124_第四周 by luckypeak · Pull Request #910 · algorithm001/algorithm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

124_第四周 #910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by ext 8000 ension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Week_04/id_124/LeetCode_169_124.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.util.List;

public class MajorityElement {

public int majorityElement(int[] nums) {
int cnt = 1;
int result = nums[0];
for (int i = 1; i < nums.length ; i++){
if (nums[i] == result){
cnt ++;
if (cnt > nums.length /2){
return result;
}
}else {
cnt --;
}
if (cnt <= 0 ){
result = nums[i];
cnt = 1;
}
}

return result;
}

public List<Integer> majorityElement2(int[] nums) {

return null;
}

public static void main(String[] args) {

}
}
19 changes: 19 additions & 0 deletions Week_04/id_124/LeetCode_746_124.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class MinCostClimbingStairs {

public int minCostClimbingStairs(int[] cost) {
if (cost.length == 2) {
return Math.min(cost[0], cost[1]);
}
int[] dp = new int[cost.length + 1];
dp[0] = cost[0];
dp[1] = cost[1];
for (int i = 2; i < cost.length; i++) {
dp[i] = Math.min(dp[i - 2], dp[i - 1]) + cost[i];
}
return Math.min(dp[cost.length - 1], dp[cost.length - 2]);
}




}
0