You are given an integer array nums.You are allowed to delete any number of elements from nums without making it empty.After performing the deletions, select a subarray of nums such that:All elements in the subarray are unique.The sum of the elements in the subarray is maximized.Return the maximum sum of such a subarray.
ودي الحل بتاعي هل يوجد افضل من كده
max_sum = float('-inf')
current_sum =0if len(array)!= len(set(array)):for num in set(array):
current_sum += num
max_sum = max(max_sum, current_sum)if current_sum <0:
current_sum =0else:for num in array:
current_sum += num
max_sum = max(max_sum, current_sum)if current_sum <0:
current_sum =0
السؤال
Ali Ahmed55
السلام عليكم
دي المساله
ودي الحل بتاعي هل يوجد افضل من كده
5 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.