| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 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
													
											
												
												- Problem Solving
 - realclass
 - 잡생각
 - 화상영어
 - 30분
 - 읽기
 - 3줄정리
 - Daily Challenge
 - 링피트
 - 미드시청
 - 괜찮음
 - 리얼 클래스
 - 만화도
 - leetcode
 - 월간
 - 매일
 - 영어공부
 - 스탭퍼
 - 사이드
 - 파비최
 - 운동
 - 뭐든
 - 쓰릴오브파이트
 - 프로젝트
 - English
 - 10분
 - Writing
 - FIT XR
 - 영어원서읽기
 - 개발자
 
													Archives
													
											
												
												- Today
 
- Total
 
파비의 매일매일 공부기록
2023.07.08 Today's Challenge 본문
https://leetcode.com/problems/put-marbles-in-bags/
Put Marbles in Bags - LeetCode
Can you solve this real interview question? Put Marbles in Bags - You have k bags. You are given a 0-indexed integer array weights where weights[i] is the weight of the ith marble. You are also given the integer k. Divide the marbles into the k bags accord
leetcode.com
오랫만에 풀어봄
class Solution:
    def putMarbles(self, weights: List[int], k: int) -> int:
        n = len(weights)
        pw = [0] * (n - 1)
        for i in range(n-1):
            pw[i] = weights[i] + weights[i+1]
        pw.sort()
        answer = 0
        for i in range(k-1):
            answer += pw[n-2-i] - pw[i]
        
        return answer반응형
    
    
    
  'Problem Solving > LeetCode' 카테고리의 다른 글
| 2023.07.10 Today's Challenge (0) | 2023.07.10 | 
|---|---|
| 2023.07.09 Today's Challenge (0) | 2023.07.09 | 
| 2023.07.07 Today's Challenge (0) | 2023.07.07 | 
| 2023.07.06 Today's Challenge (0) | 2023.07.06 | 
| 2023.07.05 Today's Challenge (0) | 2023.07.05 | 
			  Comments