当前位置:网站首页>leetcode剑指offer JZ3 数组中重复的数字
leetcode剑指offer JZ3 数组中重复的数字
2022-07-24 05:22:00 【喜乐自在】

给出 vector<int>&numbers 参数
判断重复数字,若有则返回值 ,否则 返回-1;
可以根据stl标准库的set容器 调用方法即可
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param numbers int整型vector
* @return int整型
*/
int duplicate(vector<int>& numbers) {
// write code here
set<int> s1; //新建容器
for(int i=0;i<numbers.size();i++){
if(s1.count(numbers[i]))
return numbers[i];
else
s1.insert(numbers[i]);
}
return -1;
}
}; //这道题掌握了应该在看一遍链表中环的入口节点,基于数据结构的set容器使用
边栏推荐
- 10大漏洞评估和渗透测试工具
- Dameng database_ Various methods of connecting databases and executing SQL and scripts under disql
- day4-jvm
- Write the list to txt and directly remove the comma in the middle
- Day3 jvm+ sorting summary
- Day2 websocket+ sort
- Day-7 JVM end
- Lunix命令入门 - 用户及文件权限(chmod 详解)
- 力扣:1-两数之和
- JDBC初级学习 ------(师承尚硅谷)
猜你喜欢

IP笔记(8)

不租服务器,自建个人商业网站(3)

公网访问内网IIS网站服务器【无需公网IP】

HoloLens 2 开发101:创建首个HoloLens 2应用程序

本地搭建WordPress个人博客,并内网穿透发布上线 (22)

Hololens2 development: use MRTK and simulate eye tracking

Using keras and LSTM to realize time series prediction of long-term trend memory -lstnet

Headlong platform operation

ue4 换装系统3.最终成果

HoloLens 2 开发:开发环境部署
随机推荐
Hololens 2 Chinese development document MRTK V2
Calculation steps of principal component analysis
Unity2d game let characters move - Part 1
记一次高校学生账户密码的获取,从无到有
什么是单调队列
MySQL foundation - constraints
Openpose Unity 插件部署教程
Foundation of JUC concurrent programming (6) -- lock lock
Dameng database_ LENGTH_ IN_ Influence of char and charset
Accessing a two-dimensional array with a pointer
不租服务器,自建个人商业网站(1)
EXCEL 生成mysql语句批量操作
Flink restart policy
不租服务器,自建个人商业网站(如何购买域名)
Openpose2d转换3d姿态识别
Positional argument after keyword argument
Dameng database_ Small matters needing attention during use
Day-7 JVM end
Solve modularnotfounderror: no module named "cv2.aruco“
Unity(三)三维数学和坐标系统