Day1 - Array
217. Contains Duplicate
Hash Table:
dic = {}
for item in nums:
if item in dic:
return True
else:
dic[item] = True
return False
Sorting:
nums.sort()
for i in range(1,len(nums)):
if nums[i] == nums[i-1]:
return True
return False
集合set:
return len(nums) != len(set(nums))
53. Maximum Subarray
DP思想:遍历每个数包含该数和不包含该数时最大值,再取每个数最大值
if not nums: return 0
cur_max = glo_max = nums[0]
for nums in nums[1:]:
cur_max = max(nums, cur_max + nums)
glo_max = max(cur_max, glo_max)
return glo_max

这篇博客探讨了数组中重复元素的检测方法,包括使用哈希表、排序和集合的解决方案。此外,还详细解释了求解最大子数组和的动态规划策略。这些算法在数组处理中具有广泛应用。

被折叠的 条评论
为什么被折叠?



