[LeetCode&Python] Problem 217. Contains Duplicate
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.
Example 1:
Input: [1,2,3,1]
Output: true
Example 2:
Input: [1,2,3,4]
Output: false
Example 3:
Input: [1,1,1,3,3,4,3,2,4,2]
Output: true
class Solution(object):
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
return len(nums)!=len(list(set(nums)))
[LeetCode&Python] Problem 217. Contains Duplicate的更多相关文章
- 【leetcode❤python】217. Contains Duplicate
#-*- coding: UTF-8 -*- class Solution(object): def containsDuplicate(self, nums): numsdic= ...
- [LeetCode&Python] Problem 108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Fo ...
- [LeetCode&Python] Problem 387. First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...
- [LeetCode&Python] Problem 427. Construct Quad Tree
We want to use quad trees to store an N x N boolean grid. Each cell in the grid can only be true or ...
- [LeetCode&Python] Problem 371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...
- [LeetCode&Python] Problem 520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...
- [LeetCode&Python] Problem 226. Invert Binary Tree
Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 Tr ...
- [LeetCode&Python] Problem 905: Sort Array By Parity
Given an array A of non-negative integers, return an array consisting of all the even elements of A, ...
- [LeetCode&Python] Problem 1: Two Sum
Problem Description: Given an array of integers, return indices of the two numbers such that they ad ...
随机推荐
- dubbo源码分析(一)-从xml到我们认识的Java对象
项目中用的dubbo的挺多的,然后随着自己对dubbo的慢慢深入,自己也希望能够了解dubbo的底层实现,这半年来一直在看dubbo的源码,有点断断续续的,于是准备写一个dubbo源码系列的分析文章, ...
- @RequestParam的使用
来源:http://825635381.iteye.com/blog/2196911 @RequestParam: 一. 基本使用,获取提交的参数 后端代码: @RequestMapping(&quo ...
- Spring整合Hystrix
1.添加maven依赖 <dependency> <groupId>com.netflix.hystrix</groupId> <artifactId> ...
- linux:SSH最简单教程
1.简介 ssh是一种用于计算机之间的加密登录协议.用户从本地计算机用ssh协议登录另一台计算机就可以认为登录安全,中途截获密码也不会泄露. 2.原理 (1)用户发登录请求给远程主机 (2)远程主机发 ...
- CSS--margin塌陷
margin塌陷 解决方法: 1.给父级顶加上一条线,不太合适. 2.bfc block format context 设定bfc后,特定的盒子会遵循另一套语法规则,解决了margin塌陷 触发bfc ...
- day15 装饰器
关于函数的装饰器 1 .装饰器,(难点,重点) 开闭原则: 对功能的扩展开放 对代码的修改是封闭 通用装饰器语法: def wrapper(fn): def inner(*args,**kwargs) ...
- net core2 采坑-- session 缓存
引用 Microsoft.Extensions.Caching.SqlServer 可以设置存在数据库 Microsoft.Extensions.Caching.Redis 存在redis 参考 ht ...
- 网口扫盲二:Mac与Phy组成原理的简单分析(转)
1. general 下图是网口结构简图.网口由CPU.MAC和PHY三部分组成.DMA控制器通常属于CPU的一部分,用虚线放在这里是为了表示DMA控制器可能会参与到网口数据传输中. 对于上述的三部分 ...
- CAN总线(1)--初探(更新中)
前言: CAN总线可以控制可以使用Xilinx中IP核来直接实现,也可以使用专用的CAN芯片(例如:SJA1000)通过单片机和FPGA驱动控制来实现: 目前是使用控制器SJA1000来进行实现: C ...
- DOM&BOM
文档对象模型(Document Object Model) 来源:文档对象模型(Document Object Model)的历史与20世纪90年代末Netscape Navigator和Micros ...