[HackerRank][Python3] Max Array Sum
2018. 7. 18. 15:43 |
프로그래밍/HackerRank
Problem :
https://www.hackerrank.com/challenges/max-array-sum/problem
My Solution :
#!/usr/bin/env python3 def maxSubsetSum(arr): if len(arr) == 1: return arr[0] dp = [arr[0], max(arr[:2])] + [0]*(len(arr)-2) for i in range(2, len(arr)): dp[i] = max(arr[i], dp[i-1], dp[i-2]+arr[i]) return dp[-1] n = int(input()) arr = list(map(int, input().rstrip().split())) res = maxSubsetSum(arr) print(res)
'프로그래밍 > HackerRank' 카테고리의 다른 글
[HackerRank][Python3] Binary Search Tree : Lowest Common Ancestor (0) | 2018.07.20 |
---|---|
[HackerRank][Python3] Balanced Brackets (0) | 2018.07.20 |
[HackerRank][Python3] Queues: A Tale of Two Stacks (0) | 2018.07.19 |
[HackerRank][Python3] Abbreviation (0) | 2018.07.18 |
[HackerRank][Python3] Making Candies (0) | 2018.07.18 |
[HackerRank][Python3] Minimum Time Required (0) | 2018.07.17 |
[HackerRank][Python3] Pairs (0) | 2018.07.17 |
[HackerRank][Python3] Hash Tables: Ice Cream Parlor (0) | 2018.07.16 |
최근에 달린 댓글 최근에 달린 댓글