题目:
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.

思路分析:
题意是给定一个整形数组,如果里面的元素都不重复,返回false,否则返回true。以下的做法使用map作为临时存储,记录元素是否出现。

代码实现(时间复杂度O(n)):

public class Solution {public static boolean containsDuplicate(int[] nums) {Map<Integer, Boolean> map = new HashMap<>();for (int num : nums) {Object o = map.get(num);if (o == null) {map.put(num, true);} else {return true;}}return false;}
}

Leet Code OJ 217. Contains Duplicate [Difficulty: Easy]相关推荐

  1. Leet Code OJ 112. Path Sum [Difficulty: Easy]

    题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...

  2. Leet Code OJ 344. Reverse String [Difficulty: Easy]

    题目: Write a function that takes a string as input and returns the string reversed. Example: Given s ...

  3. Leet Code OJ 28. Implement strStr() [Difficulty: Easy]

    题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ne ...

  4. Leet Code OJ 125. Valid Palindrome [Difficulty: Easy]

    题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...

  5. Leet Code OJ 20. Valid Parentheses [Difficulty: Easy]

    题目: Given a string containing just the characters , determine if the input string is valid. The brac ...

  6. Leet Code OJ 1. Two Sum [Difficulty: Easy]

    题目: Given an array of integers, return indices of the two numbers such that they add up to a specifi ...

  7. Leet Code OJ 223. Rectangle Area [Difficulty: Easy]

    题目: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defin ...

  8. Leet Code OJ 189. Rotate Array [Difficulty: Easy]

    题目: Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the ar ...

  9. Leet Code OJ 66. Plus One [Difficulty: Easy]

    题目: Given a non-negative number represented as an array of digits, plus one to the number. The digit ...

最新文章

  1. python非官方的二进制扩展包下载地址
  2. 重视细节,方能得到认可
  3. 文本编辑器中菜单栏删除功能的实现
  4. ArcGIS网络分析之Silverlight客户端最近设施点分析(四)
  5. 第13章Stata Logistic回归分析
  6. 显卡性能测试软件的是,显卡性能测试软件
  7. 2019年区块链专利增速可能放缓?
  8. MXF视频文件损坏的修复方法
  9. 相分离和长链非编码RNA之间的故事Paraspeckles: Where Long Noncoding RNA Meets Phase Separation
  10. 复盘:什么是权重衰减?深度学习权重衰减
  11. 联想YOGA 13笔记本电源适配器修理
  12. 张赐荣 | 详解SAPI5语音转换扩展XMLTTS标记
  13. 在setTimeout或者ajax等异步方法中回调函数的写法与调用
  14. 【postgresql】数据聚合之PERCENTILE_CONT
  15. 华益血糖信息管理系统服务器,华益血糖信息化管理系统
  16. Keras 主要的层函数
  17. xbox360游戏下载_如何在Xbox One上玩Xbox 360游戏
  18. 信息收集之——子域信息
  19. Visual Studio Code(vs code)函数跳转及返回
  20. 什么是App个性化?App个性化安装的优势是什么?

热门文章

  1. 利用小工具instsrv和srvany 创建windows服务
  2. MFC内嵌web页面
  3. live555 源码分析:ServerMediaSession
  4. Golang 常见设计模式之装饰模式
  5. 数据结构与算法 | 用栈实现队列
  6. C语言程序设计 | 结构体,枚举,联合
  7. Win下通过 Navica t连接Ubuntu下MySQL数据库
  8. 文件句柄(file handles) 文件描述符(file descriptors)
  9. 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
  10. 打入硅谷的局外人|Decode the Week