当前位置:网站首页>[LeetCode] 存在重复元素【217】
[LeetCode] 存在重复元素【217】
2022-07-02 22:06:00 【山茶花开时。】
问题: 给你一个整数数组nums,如果任一值在数组中出现至少两次,返回True;如果数组中每个元素互不相同,返回False
示例1
输入: nums = [1,2,3,1]
输出: True
示例2
输入: nums = [1,2,3,4]
输出: False
示例3
输入: nums = [1,1,1,3,3,4,3,2,4,2]
输出: True
Python3解题
# 解法1:set去重,比较长度
def containsDuplicate(nums):
len_set_nums = len(set(nums))
if (len_set_nums != len(nums)):
return True
else:
return False
# 解法2:排序,比较是否相等
def containsDuplicate(nums):
nums.sort()
for i in range(len(nums)-1):
if nums[i+1] == nums[i]:
return True
return False
# 解法3
def containsDuplicate(nums):
if len(nums) <= 1:
return False
hashset = set()
for i in nums:
if i in hashset:
return True
else:
hashset.add(i)
return False
containsDuplicate([1,2,3,1]) # True
containsDuplicate([1,2,3,4]) # False
containsDuplicate([1,1,1,3,3,4,3,2,4,2]) # True边栏推荐
- Try to get property'num for PHP database data reading_ rows' of non-object?
- Service visibility and observability
- 540. Single element in ordered array
- Market Research - current situation and future development trend of marine clutch Market
- Lightgbm principle and its application in astronomical data
- Radis:Linux上安装Redis(步骤)
- Simpleitk use - 3 Common operations
- [shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)
- Oracle cursor
- 原生js添加样式的方法
猜你喜欢

基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习

Oracle-PL/SQL编程

phpcms实现订单直接支付宝支付功能

电商系统微服务架构
![Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)](/img/b7/0f543829b57cf2f2544efec4910c17.png)
Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)
![[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)](/img/2b/f31b81cedf37ca187bcaa20dfe0b83.png)
[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)

Basic concepts of image and deep understanding of yuv/rgb

Scrcpy this software solves the problem of sharing mobile screen with colleagues | community essay solicitation
![[shutter] shutter resource file use (import resource pictures | use image resources)](/img/e9/94ae2e3ee315f490eb3cf14bcf2e49.jpg)
[shutter] shutter resource file use (import resource pictures | use image resources)

Commodity information management system (C language document version)
随机推荐
牛客网:龙与地下城游戏
How should programmers write logs
杰理之快速触摸不响应问题【篇】
Market Research - current market situation and future development trend of intravenous injection (IV) bottles
杰理之、产线装配环节【篇】
Using emqx cloud to realize one machine one secret verification of IOT devices
佩服,竟然有人把高等数学这么晦涩难懂的科目,讲解得如此通俗易懂
[001] [arm-cortex-m3/4] internal register
Technological Entrepreneurship: failure is not success, but reflection is
Notes on key vocabulary of the original English book biography of jobs (IX) [chapter seven]
Perceptron model and Application
App page sharing password rails implementation
Sql service intercepts string
PHP wechat red packet grabbing algorithm
Oracle PL / SQL programming
Market Research - current situation and future development trend of anterior cruciate ligament (ACL) reconstruction Market
Based on asp Net (used mobile phone sales management system) +asp Net+c # language +vs2010+ database can be used for course design and post design learning
Introduction to database system Chapter 1 short answer questions - how was the final exam?
Objects and object variables
Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?