IN PYTHON CODE ONLY & PLEASE SHOW
OUTPUT
Question 2:
There are piles of coins on the table. The number of coins in
each pile is known. Please pick up piles to maximize the number of
coins. The restriction is that you cannot pick up coins from
consecutive two piles. The last pile and the first pile are not
connected. Using other methods will not receive any
credit.
Example: Input: [2,7,9,3,1] Output: 12 Explanation: pick up the
first, the third, and the fifth: 2+9+1=12
Q2.py:
class Solution(object):
def pick(self, nums):
"""
input: int list, numbers of
coins
output: maximum number
"""
return maximum
if __name__ == "__main__":
res = Solution().pick([1, 2, 3, 4, 5, 6, 7])
if res == 16:
print('PASS')
IN PYTHON CODE ONLY & PLEASE SHOW OUTPUT Question 2: There are piles of coins on the table. The number of coins in each
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
IN PYTHON CODE ONLY & PLEASE SHOW OUTPUT Question 2: There are piles of coins on the table. The number of coins in each
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!