1. pythonic
def cutTheSticks(arr):
# Write your code here
arr.sort(reverse = True)
sticks_cut = []
while arr:
sticks_cut.append(len(arr))
min_value = arr.pop()
while arr and min_value == arr[-1]:
arr.pop()
return sticks_cut
2. 구식
def cutTheSticks(arr):
# Write your code here
sticks_cut = []
while len(arr) > 1:
cutoff = min(arr)
sticks_cut.append(len(arr))
arr = [num - cutoff for num in arr]
temp_arr = []
for num in arr:
if not num:
continue
temp_arr.append(num)
arr = temp_arr
if len(arr) == 1:
sticks_cut.append(1)
return sticks_cut
'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글
[HackerRank-python] Repeated String (0) | 2022.08.22 |
---|---|
[HackerRank-python] Non-Divisible Subset (0) | 2022.08.14 |
[HackerRank-python] Library Fine (0) | 2022.08.09 |
[HackerRank-python] Sherlock and Squares (0) | 2022.08.09 |
[HackerRank-python] Append and Delete (0) | 2022.08.03 |