当前位置:网站首页>Array to determine any duplicate value
Array to determine any duplicate value
2022-06-10 10:33:00 【InfoQ】
1、 Background
2、 Code implementation
public class Solution {
public static void main(String[] args) {
int[] nums = new int[]{-2, 1, -3, 4, -1, 2, 1, -5, 4};
// System.out.println(containsDuplicate(nums));
System.out.println(containsDuplicate(nums));
}
/**
* Give you an array of integers nums, If any value appears in the array at least twice , return true; If each element in the array is different from each other , return false
*
* @param nums
* @return
*/
public static boolean containsDuplicate(int[] nums) {
Set set = new HashSet();
for (int i : nums) {
set.add(i);
}
return nums.length > set.size() ? true : false;
}
}
3、 Result display
true
Process finished with exit code 0
边栏推荐
- Xcode8.3.2 automatic packaging script
- Some problems in using message queue service in thinkphp6
- Concurrent asyncio asynchronous programming
- 【高并发】关于乐观锁和悲观锁,蚂蚁金服面试官问了我这几个问题!!
- 62. 不同路径-动态规划
- mdb转换为db文件
- [high concurrency] about optimistic lock and pessimistic lock, the interviewer of ant financial asked me these questions!!
- Hardcore spoiler! With 11 topics and 14 celebrities, dragon dragon dragon community entered Intel meetup and announced the agenda!
- 仿淘宝商品详情,下拉切换到图片详情,上拉切换到图文简介
- 一个独特的简历生成器,开源了!
猜你喜欢

Introduction to development technology of multi-target application on SAP cloud platform

「诗经」主题文化数字藏品中奖名单公布

怎样简洁明了地说清楚产品需求?

Academic lecture: masp for multi label active learning

62. 不同路径-动态规划

Leetcode 1991. 找到数组的中间位置(暴力枚举)

效率工具 : uTools
常用Shell命令 - 02 压缩和解压缩
![[interesting reading] deepinf: social influence prediction with deep learning](/img/67/2a90dea2f129245c4a60a5e079340f.png)
[interesting reading] deepinf: social influence prediction with deep learning

Hardcore spoiler! With 11 topics and 14 celebrities, dragon dragon dragon community entered Intel meetup and announced the agenda!
随机推荐
2023 Wangdao C language training camp (binary search tree - sequential search - half search)
MAC下安装MySQL+Django详细步骤
PV操作每日一题-橘子苹果问题(进阶版)
Array target two integers and return their array subscripts
All things grow and each is noble
Mixin -- mixed
vite的public目录
PV操作每日一题-缓冲区问题
硬核剧透!11个议题、14位大咖,龙蜥社区走进 Intel MeetUp 议程公布!
9、 Delegation mode
PV操作每日一题-黑白棋子问题(变式)
【高并发】关于乐观锁和悲观锁,蚂蚁金服面试官问了我这几个问题!!
2021 ciscn-pwn 初赛
fcpx插件:PremiumVFX Animation Presets(动画循环预设) v1.0.1特别版
Splishsplash架构介绍
ApiPost的环境变量的定义和使用「ApiPost环境变量」
How long has elapsed to show the time
6、 Observer mode
rt-thread 使用宝典(2022-0516更新)
MDB to DB file