217 Contains Duplicate (Array)

 1 class Solution {
 2     public boolean containsDuplicate(int[] nums) {
 3         HashMap<Integer, Integer> m = new HashMap<Integer, Integer>();
 4         for(int i = 0; i < nums.length; i++) {
 5             if (m.containsKey(nums[i])) {
 6                 return true;
 7             }else {
 8                 m.put(nums[i], 1);
 9             }
10         }
11         return false;
12     }
13 }

原文地址:https://www.cnblogs.com/goPanama/p/9375119.html

时间: 2024-10-14 06:21:32

217 Contains Duplicate (Array)的相关文章

217. Contains Duplicate(C++)

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. 题目大意: 给定一个整数数组,

leetCode 217. Contains Duplicate 数组

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. 题目大意: 在数组中找到任意字

leetcode 217. Contains Duplicate 287. Find the Duplicate Number

217. Contains Duplicate 后面3个题都是限制在1-n的 class Solution { public: bool containsDuplicate(vector<int>& nums) { int length = nums.size(); if(length <= 0) return false; sort(nums.begin(),nums.end()); for(int i = 1;i < length;i++){ if(nums[i] ==

[Array]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. 思路:只要一个整数数组中某个元素出现两次及以上,返回true,否则返回fals

LeetCode # Array # Easy # 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. 题目:给定一个数组,判断其中有无重复元素,返回true或false. 思路:首

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

 Contains Duplicate Total Accepted: 26477 Total Submissions: 73478 My Submissions 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 shoul

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

?? Contains Duplicate Total Accepted: 26477 Total Submissions: 73478 My Submissions 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 shoul

【LeetCode】217. Contains Duplicate (2 solutions)

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. 解法一: 排序,然后比较相邻元素是否相同

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. 给定整数数组,查找数组是否包含任何重复项. 如果数组中的任何值至少出现两次,则