[Python] Thinking from presum
Given a list of numbers, the maximum we could reach is the sum of the array. What if we keep trying from left to right (after sorting)? For every coins[i], it c
Given a list of numbers, the maximum we could reach is the sum of the array. What if we keep trying from left to right (after sorting)? For every coins[i], it can construct every number from `coins[i]` to `coins[i] + persum[i-1]`.\n\n```\n    def getMaximumConsecutive(self, coins):\n        """\n        :type coins: List[int]\n        :rtype: int\n        """\n        coins.sort()\n        persum = [0] * len(coins)\n        ans = 1\n        for i,c in enumerate(coins):\n            persum[i] += persum[i-1] + c\n\n        if persum[0] != 1:\n            return ans\n        ans += 1\n        for i in range(1,len(persum)):\n            if persum[i] == ans:\n                ans += 1\n            elif coins[i] <= ans:\n                ans = persum[i] + 1\n            else:\n                return ans\n        return ans\n```\n\nFrom the code above, we can see that ans is actually exactly persum, so we don\'t need a list of persum anymore.\n\n```\n    def getMaximumConsecutive(self, coins):\n        """\n        :type coins: List[int]\n        :rtype: int\n        """\n        ans = 1\n        for coin in sorted(coins):\n            if coin <= ans:\n                ans += coin\n            else:\n                return ans\n        return ans\n```
['Python']