Leetcode#217Contains Duplicate

Contains Duplicate

Total Accepted: 1202 Total Submissions: 3067My Submissions

Question Solution

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.

Show Tags

Have you met this question in a real interview?

Yes

No

Discuss

public class Solution {

public boolean containsDuplicate(int[] nums) {

Map<Integer,Integer> x=new HashMap<Integer, Integer>();

for(int i=0;i<nums.length;i++)

{

if(x.get(nums[i])==null)

{

x.put(nums[i],1);

}

else

return true;

}

return false;

}

}

时间: 2024-10-11 22:07:30

Leetcode#217Contains Duplicate的相关文章

【LeetCode-面试算法经典-Java实现】【217-Contains Duplicate(包含重复元素)】

[217-Contains Duplicate(包含重复元素)] [LeetCode-面试算法经典-Java实现][所有题目目录索引] 代码下载[https://github.com/Wang-Jun-Chao] 原题 Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice

[LeetCode] Remove Duplicate Letters 移除重复字母

Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order among all possible results. Example: Given "bcabc&q

[LeetCode] Delete Duplicate Emails 删除重复邮箱

Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id. +----+------------------+ | Id | Email | +----+------------------+ | 1 | [email protected] | | 2 | [email protected]

[LeetCode][SQL]Duplicate Emails

https://leetcode.com/problems/duplicate-emails/ Duplicate Emails Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Email | +----+---------+ | 1 | [email protected] | | 2 | [email protected] | | 3 | [email

【Leetcode】Duplicate Emails

题目链接:https://leetcode.com/problems/duplicate-emails/ 题目: Write a SQL query to find all duplicate emails in a table named Person. +--+---+ | Id | Email | +--+---+ | 1 | [email protected] | | 2 | [email protected] | | 3 | [email protected] | +--+---+ F

LeetCode:Duplicate Emails - 重复出现的Email

1.题目名称 Duplicate Emails(重复出现的Email) 2.题目地址 https://leetcode.com/problems/duplicate-emails/ 3.题目内容 有一个数据表包括Id和Email两列,找出数据表内Email列内容重复出现的Email数据. 例如,现有一个表Person内容如下: +----+---------+ | Id | Email   | +----+---------+ | 1  | [email protected] | | 2  | 

[leetcode] Remove Duplicate Letters

题目: Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order among all possible results. Example: Given "bca

[LeetCode] Contains Duplicate II 包含重复值之二

Given an array of integers and an integer k, return true if and only if there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k. 这道题是之前那道Contains Duplicate 包含重复值的延伸,不同之处在于那道题只要我们

LeetCode - Delete Duplicate Emails

Discription:Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id. 删除重复的Email地址,保留Id最小的那个. 使用自身连接循环即可. # Write your MySQL query statement below delete p1 from Person p1, P