Skip to content

Commit beadc5e

Browse files
solves min cost climbing stairs
1 parent cc96000 commit beadc5e

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# LeetCode Algorithms
22

3-
![problems-solved](https://img.shields.io/badge/Problems%20Solved-178/2081-1f425f.svg)
4-
![problems-solved-java](https://img.shields.io/badge/Java-178/2081-1abc9c.svg)
5-
![problems-solved-python](https://img.shields.io/badge/Python-178/2081-1abc9c.svg)
3+
![problems-solved](https://img.shields.io/badge/Problems%20Solved-181/2081-1f425f.svg)
4+
![problems-solved-java](https://img.shields.io/badge/Java-181/2081-1abc9c.svg)
5+
![problems-solved-python](https://img.shields.io/badge/Python-181/2081-1abc9c.svg)
66
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
77
[![cp](https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg)](https://github.com/anishLearnsToCode/competitive-programming)
88

@@ -201,10 +201,10 @@
201201
| 720 | [Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary) | |
202202
| 724 | [Find Pivot Index](https://leetcode.com/problems/find-pivot-index) | [![Java](assets/java.png)](src/FindPivotIndex.java) [![Python](assets/python.png)](python/find_pivot_index.py) |
203203
| 728 | [Self Dividing Numbers](https://leetcode.com/problems/self-dividing-numbers) | [![Java](assets/java.png)](src/SelfDividingNumbers.java) [![Python](assets/python.png)](python/self_dividing_number.py) |
204-
| 733 | [Flood Fill](https://leetcode.com/problems/flood-fill) | [![Java](assets/java.png)](src/FloodFill.java) [![Python](assets/python.png)](python/) |
204+
| 733 | [Flood Fill](https://leetcode.com/problems/flood-fill) | [![Java](assets/java.png)](src/FloodFill.java) [![Python](assets/python.png)](python/flood_fill.py) |
205205
| 734 | [Sentence Similarity](https://leetcode.com/problems/sentence-similarity) | |
206-
| 744 | [Find Smallest Letter Greater Than Target](https://leetcode.com/problems/find-smallest-letter-greater-than-target) | |
207-
| 746 | [Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs) | |
206+
| 744 | [Find Smallest Letter Greater Than Target](https://leetcode.com/problems/find-smallest-letter-greater-than-target) | [![Java](assets/java.png)](src/FindSmallestLetterGreaterThanTarget.java) [![Python](assets/python.png)](python/find_smallest_letter_greater_than.py) |
207+
| 746 | [Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs) | [![Java](assets/java.png)](src/MinCostClimbingStairs.java) [![Python](assets/python.png)](python/min_cost_climbing_stairs.py) |
208208
| 747 | [Largest Number at least twize of Others](https://leetcode.com/problems/largest-number-at-least-twice-of-others) | |
209209
| 748 | [Shortest Completing Word](https://leetcode.com/problems/shortest-completing-word) | |
210210
| 758 | [Bold Words in String](https://leetcode.com/problems/bold-words-in-string) | |

python/min_cost_climbing_stairs.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def minCostClimbingStairs(self, cost: List[int]) -> int:
6+
previousCost, currentCost = cost[0], cost[1]
7+
index = 2
8+
while index < len(cost):
9+
previousCost, currentCost = currentCost, min(previousCost, currentCost) + cost[index]
10+
index += 1
11+
return min(previousCost, currentCost)

src/MinCostClimbingStairs.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class MinCostClimbingStairs {
2+
public int minCostClimbingStairs(int[] cost) {
3+
int currentCost = cost[1], previousCost = cost[0], temp;
4+
for (int index = 2 ; index < cost.length ; index++) {
5+
temp = currentCost;
6+
currentCost = Math.min(currentCost, previousCost) + cost[index];
7+
previousCost = temp;
8+
}
9+
return Math.min(previousCost, currentCost);
10+
}
11+
}

0 commit comments

Comments
 (0)