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
想法:先对数组排序,然后判断相邻两个元素是否相等。相等返回true,否则返回false
class Solution {
public:
    bool containsDuplicate(vector<int>& nums) {
         == nums.size())
            return false;
        sort(nums.begin(),nums.end());
         ; i < nums.size() ; i++){
            )){
                return true;
            }
        }
        return false;
    }
};

leetcode 217—Contains Duplicate的更多相关文章

  1. 25. leetcode 217. Contains Duplicate

    217. Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your ...

  2. leetcode 217. Contains Duplicate 287. Find the Duplicate Number 442. Find All Duplicates in an Array 448. Find All Numbers Disappeared in an Array

    后面3个题都是限制在1-n的,所有可以不先排序,可以利用巧方法做.最后两个题几乎一模一样. 217. Contains Duplicate class Solution { public: bool ...

  3. LN : leetcode 217 Contains Duplicate

    lc 217 Contains Duplicate 217 Contains Duplicate Given an array of integers, find if the array conta ...

  4. [LeetCode] 217. Contains Duplicate 包含重复元素

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  5. LeetCode 217. Contains Duplicate (包含重复项)

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  6. leetcode 217 Contains Duplicate 数组中是否有重复的数字

     Contains Duplicate Total Accepted: 26477 Total Submissions: 73478 My Submissions Given an array o ...

  7. leetcode 217 Contains Duplicate 数组中是否有反复的数字

     Contains Duplicate Total Accepted: 26477 Total Submissions: 73478 My Submissions Given an array o ...

  8. Java for LeetCode 217 Contains Duplicate

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  9. LeetCode 217 Contains Duplicate

    Problem: Given an array of integers, find if the array contains any duplicates. Your function should ...

  10. (easy)LeetCode 217.Contains Duplicate

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

随机推荐

  1. ubuntu 17.10 安装后的应用软件安装

    目录 安装 sogou 拼音 安装markdown编辑器 安装codeblocks 下载工具uGet+aira2 安装QT 安装remarkable(markdown工具) 安装StarUML(UML ...

  2. Linux常用基本命令[cp]

    cp:复制文件或者目录 用法格式: cp [option] [source] [dest] cp [选项] [源文件] [目标文件] >用root账户,创建文件,复制文件 root@dev:/h ...

  3. deferred对象详解

    什么是Deferred对象  defer,推迟:延期.含义就是”延迟”到未来某个点再执行. 在开发中,我们经常遇到某些耗时很长的javascript操作.其中,既有异步的操作(比如ajax读取服务器数 ...

  4. Python数据模型

    引言 像大多数人一样,我在对一直传统的面向过程语言C一知半解之后,走进了面向对象的世界,尽管对OOP一无所知,还好Python还保留有函数式编程,这使得我才不那么抵触,直到现在,习惯了面向对象之后,也 ...

  5. JS实现选择菜单栏(配合慕课网淘宝搜索框的课程)

    以下是关于实现慕课网淘宝搜索框的JS代码,不过只有选择菜单栏(其余比较容易实现). <!doctype html> <html> <head> <!--在IE ...

  6. 说说gogoTester-nodejs 的实现

    一直在使用goagent,所以对于查找google可用ip有了很大的兴趣,在github上面发现有一个项目是gogoTester,是用来查找google ip的,于是突发奇想自己用nodejs写了一个 ...

  7. CentOS7下 将django工程部署到Apache2.4上

    因为需要写一个网站,考虑到也没写过其他的语言,就直接采用了python,说起python的框架,就是大名鼎鼎的Django啦. 工程所采用的版本是python 2.7,django 是1.8,wind ...

  8. JS--我发现,原来你是这样的JS(四)(看看变量,作用域,垃圾回收机制是啥)

    一.介绍 这是红宝书(JavaScript高级程序设计 3版)的读书笔记第四篇,是红宝书第四章内容(主要是变量和作用域问题),当然其中还有我个人的理解.红宝书这本书可以说是难啃的,要看完不容易,挺厚的 ...

  9. VideoView获取本地视频播放

    主布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...

  10. [iOS] Win8下在Vmware11中安装使用苹果系统OS X 10.10

      近来因为人事变动,领导打算安排我做 iOS 的项目,所以需要花一些时间提前准备一下iOS相关的东西.因为自己手头上并没有 Mac(过年为了闲的时候能玩玩游戏买了联想,唉),想想不能只靠每天在公司的 ...