[LeetCode] 746. Min Cost Climbing Stairs

2023. 8. 15. 23:38·Problem Solving/LeetCode

출처 : https://leetcode.com/problems/min-cost-climbing-stairs/description/?envType=study-plan-v2&envId=dynamic-programming 

 

Min Cost Climbing Stairs - LeetCode

Can you solve this real interview question? Min Cost Climbing Stairs - You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps. You can either start from the ste

leetcode.com

 

 

class Solution:
    def minCostClimbingStairs(self, cost: List[int]) -> int:
        dp = [0] * len(cost)
        dp[0] = cost[0]
        if len(cost) >= 2 : 
            dp[1] = cost[1]
        for i in range(2,len(cost)) :
            dp[i] = cost[i] + min(dp[i-1], dp[i-2])
       
        return min(dp[-1], dp[-2])

 

'Problem Solving/LeetCode' 카테고리의 다른 글
  • [LeetCode] 36. Valid Sudoku
  • [LeetCode] 347. Top K Frequent Elements
  • [LeetCode] 49. Group Anagrams
  • [LeetCode] 2811. Check if it is Possible to Split Array
kimdozzi
kimdozzi
끝까지 포기하지 않으면, 내가 다 이겨!
  • kimdozzi
    도브로
    kimdozzi
  • 전체
    오늘
    어제
    • 분류 전체보기 (132)
      • Problem Solving (49)
        • Baekjoon (29)
        • Programmers (0)
        • LeetCode (17)
        • 삼성 유형 (2)
      • Computer Science (27)
        • Operating System (2)
        • Algorithms (13)
        • Network (6)
        • DataBase (6)
      • Backend (33)
        • JavaScript (0)
        • TypeScript (6)
        • Java (7)
        • Spring Boot (7)
        • Spring Security (6)
        • JPA (2)
        • Mybatis (1)
        • Junit5 (1)
        • Redis (3)
      • DevOps (14)
        • Git, Github (5)
        • docker (4)
        • AWS (3)
        • nginx (2)
      • etc (6)
        • IntelliJ (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 티스토리
    • 설정
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    도커
    인덱서블 타입
    PrefixSum
    AWS
    구간 업데이트
    백준
    인덱스 시그니처
    점 업데이트
    python
    알고리즘
    삼성기출
    오프라인 쿼리
    오블완
    파이썬
    CORS
    온라인 쿼리
    S3
    구간합
    imos법
    interface
    Bucket
    TypeScript
    segment tree
    docker image
    docker
    인터페이스
    세그먼트 트리
    티스토리챌린지
    누적합
    타입스크립트
    컨테이너
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
kimdozzi
[LeetCode] 746. Min Cost Climbing Stairs
상단으로

티스토리툴바