# 코딩 문제 관련/파이썬
[HackerRank-python] Cut the sticks
Hwiyong Jo
2022. 8. 11. 22:49
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