Find Subsequence of Length K With the Largest Sum LeetCode solution in Python

1
class Solution(object):
2
def maxSubsequence(self, nums, k):
3
ret, max_k = [], sorted(nums, reverse=True)[:k]
4
for num in nums:
5
if num in max_k:
6
ret.append(num)
7
max_k.remove(num)
8
if len(max_k) == 0:
9
return ret

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0