- Notifications
You must be signed in to change notification settings - Fork 0
[leetcode]217.存在重复元素 #40
Copy link
Copy link
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Description
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
方法一:排序
在对数字从小到大排序之后。数组的重复元素一定出现在相邻的位置,因此我们可以扫描已经排序的数组,每次判断相邻的两个元素是否相等,如果相等则说明存在重复的元素。
复杂度分析
方法二:哈希表
对于数组中的每个元素,我们将它插入到哈希表中,如果插入一个元素的时候发现这个元素已经存在于哈希表中,则说明存在重复的元素。
复杂度分析: