일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 미드시청
- 리얼 클래스
- 읽기
- 3줄정리
- 영어원서읽기
- leetcode
- 화상영어
- 만화도
- 사이드
- 개발자
- 쓰릴오브파이트
- Writing
- 스탭퍼
- 잡생각
- 운동
- 파비최
- Problem Solving
- 괜찮음
- 매일
- 10분
- 뭐든
- 월간
- 프로젝트
- realclass
- FIT XR
- 30분
- Daily Challenge
- English
- 영어공부
- 링피트
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.12.28 Today's Challenge 본문
https://leetcode.com/problems/minimum-time-to-make-rope-colorful/
Minimum Time to Make Rope Colorful - LeetCode
Can you solve this real interview question? Minimum Time to Make Rope Colorful - Alice has n balloons arranged on a rope. You are given a 0-indexed string colors where colors[i] is the color of the ith balloon. Alice wants the rope to be colorful. She does
leetcode.com
완탐으로 푸는 문제
class Solution:
def minCost(self, colors: str, neededTime: List[int]) -> int:
total, i, j = 0, 0, 0
while i < len(neededTime) and j < len(neededTime):
cur_total, cur_max = 0, 0
while j < len(neededTime) and colors[i] == colors[j]:
cur_total += neededTime[j]
cur_max = max(cur_max, neededTime[j])
j += 1
total += cur_total - cur_max
i = j
return total
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.12.30 Today's Challenge (0) | 2023.12.30 |
---|---|
2023.12.29 Today's Challenge (0) | 2023.12.29 |
2023.12.27 Today's Challenge (0) | 2023.12.27 |
2023.12.26 Today's Challenge (0) | 2023.12.26 |
2023.12.25 Today's Challenge (1) | 2023.12.25 |