217. Contains Duplicate *
来源:互联网 发布:淘宝怎么判定定制产品 编辑:程序博客网 时间:2024/05/18 22:44
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
My code:
class Solution(object): def containsDuplicate(self, nums): """ :type nums: List[int] :rtype: bool """ n = len(nums) if len(nums)<2: return False nums.sort() for i in range(1,n): if nums[i]== nums[i-1]: return True return False
If the dictionary is used to find the duplicates, there would be a lot of searching about the keys. So the list should be sorted first to save time.
0 0
- 217. Contains Duplicate
- LeetCode 217. Contains Duplicate
- [leetcode] 217.Contains Duplicate
- 217.Contains Duplicate
- 【leetcode】217. Contains Duplicate
- 【Leetcode】217. Contains Duplicate
- [LeetCode]217. Contains Duplicate
- 217. Contains Duplicate LeetCode
- 217. Contains Duplicate
- LeetCode 217. Contains Duplicate
- 217. Contains Duplicate
- 217. Contains Duplicate
- 217. Contains Duplicate
- [LeetCode]217. Contains Duplicate
- 【LeetCode】217. Contains Duplicate
- 217. Contains Duplicate
- 217. Contains Duplicate
- leetcode 217. Contains Duplicate
- hrbust 1697 国际象棋【二分匹配】
- MySQL安装教程及其常见问题
- 欢迎使用CSDN-markdown编辑器
- Shiro登录成功之后跳到指定URL
- JS中typeof与instanceof的区别
- 217. Contains Duplicate *
- 机房合作之外观模式浅谈
- thrift介绍及应用(二)—简单应用
- Android AIDL的使用
- 月溅星河长路漫漫,风烟残尽独影阑珊——又是一年
- POJ 2377 最大生成树
- Mysql----Join用法(Inner join,Left join,Right join, Cross join, Union模拟Full join)及---性能优化
- Codeforces 429B B. Working out (DP)
- java类的加载 初始化时机,已经静态代码块的执行时机