상위 150개 인터뷰중간

최소 비용 등반 계단

'최소 계단 오르기 비용' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

중간

비용[i]이 계단의 i번째 단계 비용인 정수 배열 비용이 제공됩니다. 비용을 지불하면 한 계단 또는 두 계단 올라갈 수 있습니다.

인덱스가 0인 단계에서 시작하거나 인덱스가 1인 단계에서 시작할 수 있습니다.

바닥의 꼭대기에 도달하기 위한 최소 비용을 반환합니다.

minCostClimbingStairs(cost: List[int]) -> int 함수를 작성하세요.

제약
  • 2 <= len(cost) <= 1000
  • 0 <= cost[i] <= 999

Example 1
Input
cost = [10,15,20]
Output
15
Explanation

Start at index 1, pay 15, and climb to the top. Total is 15.

Example 2
Input
cost = [1,100,1,1,1,100,1,1,100,1]
Output
6
Explanation

Start at index 0, pay 1, climb to 2, pay 1, climb to 4, pay 1, climb to 6, pay 1, climb to 7, pay 1, climb to 9, pay 1, climb to top. Total is 6.

Need a Hint?
세트나 힙과 같은 1D DP 관련 데이터 구조를 사용해 보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.