2020년/코테
[코테 연습] Maximum Number of Coins You Can Get
위지원
2020. 9. 9. 16:38
https://leetcode.com/problems/maximum-number-of-coins-you-can-get/
Maximum Number of Coins You Can Get - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows:
- In each step, you will choose any 3 piles of coins (not necessarily consecutive).
- Of your choice, Alice will pick the pile with the maximum number of coins.
- You will pick the next pile with maximum number of coins.
- Your friend Bob will pick the last pile.
- Repeat until there are no more piles of coins.
Given an array of integers piles where piles[i] is the number of coins in the ith pile.
Return the maximum number of coins which you can have.
문제 푸는데 걸린 시간 : 20분
문제 이해를 잘못해서 헛수고했다 10분이나 ㅡㅡ;;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def maxCoins(self, piles: List[int]) -> int: | |
piles = sorted(piles,reverse=True)[:int(len(piles)*2/3)] | |
res = 0 | |
for i in range(1, len(piles), 2): | |
res += piles[i] | |
return res |