Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- python zip_longest
- binary search
- 파이썬알고리즘
- 상가수익률계산기
- 파이썬 릿코드
- python xor
- 파이썬 알고리즘
- python 알고리즘
- python sorted
- python 릿코드
- 릿코드 파이썬
- 알고리즘풀기
- 알고리즘풀이
- python Leetcode
- 릿코드풀이
- 잇츠디모
- leetcode풀기
- 파이썬알고리즘풀기
- LeetCode
- leetcode 풀기
- 파이썬릿코드풀기
- leetcode풀이
- 릿코드
- 릿코드풀기
- python priority queue
- 파이썬 알고리즘 풀기
- 릿코드 풀기
- 코틀린기초
- 파이썬 프로그래머스
- 파이썬릿코드
Archives
- Today
- Total
소프트웨어에 대한 모든 것
LeetCode 풀이 - 1769. Minimum Number of Operations to Move All Balls to Each Box 본문
알고리즘/LeetCode
LeetCode 풀이 - 1769. Minimum Number of Operations to Move All Balls to Each Box
앤테바 2021. 10. 19. 00:00반응형
1769. Minimum Number of Operations to Move All Balls to Each Box
문제)
솔루션1)
class Solution:
def minOperations(self, boxes: str) -> List[int]:
res = [0] * len(boxes)
for i in range(len(boxes)):
for j in range(len(boxes)):
if i == j:
continue
if boxes[j] == '1':
res[i] += abs(i - j)
return res
솔루션2)
class Solution:
def minOperations(self, boxes: str) -> List[int]:
res = [0] * len(boxes)
fill_idxs = []
for idx, ch in enumerate(boxes):
if ch == '1':
fill_idxs.append(idx)
for i in range(len(boxes)):
for j in fill_idxs:
if i == j:
continue
if boxes[j] == '1':
res[i] += abs(i - j)
return res
반응형
'알고리즘 > LeetCode' 카테고리의 다른 글
LeetCode 풀이 - 1773. Count Items Matching a Rule (0) | 2021.10.19 |
---|---|
LeetCode 풀이 - 2006. Count Number of Pairs With Absolute Difference K (0) | 2021.10.19 |
LeetCode 풀이 - 1528. Shuffle String (0) | 2021.10.18 |
LeetCode 풀이 - 1828. Queries on Number of Points Inside a Circle (0) | 2021.10.16 |
LeetCode 풀이 - 1672. Richest Customer Wealth (0) | 2021.10.16 |
Comments