当前位置:网站首页>There are duplicate elements in leetcode. Go implementation
There are duplicate elements in leetcode. Go implementation
2022-07-02 05:00:00 【Jimmy_ jimi】
The goal is : There are duplicate elements
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 .
Result output :
### Brute force
func containsDuplicate(nums []int) bool {
flag := false
re:
for i:=0;i<len(nums);i++{
for j:=i+1;j<len(nums);j++{
if nums[i] == nums[j]{
flag =true
break re
}
}
}
return flag
}
Usage sort sort.Ints
func containsDuplicate(nums []int) bool {
sort.Ints(nums)
for i := 1; i < len(nums); i++ {
if nums[i] == nums[i-1] {
return true
}
}
return false
}
Use hash surface
func containsDuplicate(nums []int) bool {
set := map[int]struct{
}{
}
for _, v := range nums {
//set The key value in the table is equal to has Value
if _, has := set[v]; has {
return true
}
set[v] = struct{
}{
}
}
return false
}
边栏推荐
- 國產全中文-自動化測試軟件Apifox
- Idea autoguide package and autodelete package Settings
- C - derived classes and constructors
- geotrust ov多域名ssl证书一年两千一百元包含几个域名?
- Typescript function details
- Steam教育的实际问题解决能力
- Video multiple effects production, fade in effect and border background are added at the same time
- Cubemx DMA notes
- Mouse events in JS
- 数学问题(数论)试除法做质数的判断、分解质因数,筛质数
猜你喜欢
Express logistics quick query method, set the unsigned doc No. to refresh and query automatically
将光盘中的cda保存到电脑中
Several methods of capturing packets under CS framework
2022-003arts: recursive routine of binary tree
Line by line explanation of yolox source code of anchor free series network (7) -- obj in head_ loss、Cls_ Loss and reg_ Calculation and reverse transmission of loss I
Pit encountered in win11 pytorch GPU installation
How to recover deleted data in disk
数学知识(欧拉函数)
Future trend of automated testing ----- self healing technology
Pytest learning ----- pytest Interface Association framework encapsulation of interface automation testing
随机推荐
Leetcode- insert and sort the linked list
Idea automatic package import and automatic package deletion settings
Feign realizes file uploading and downloading
Super detailed pycharm tutorial
Several methods of capturing packets under CS framework
How do I interview for a successful software testing position? If you want to get a high salary, you must see the offer
leetcode两数相加go实现
Line by line explanation of yolox source code of anchor free series network (7) -- obj in head_ loss、Cls_ Loss and reg_ Calculation and reverse transmission of loss I
Win10 disk management compressed volume cannot be started
geotrust ov多域名ssl證書一年兩千一百元包含幾個域名?
设置滚动条默认样式 谷歌浏览器
A new attribute value must be added to the entity entity class in the code, but there is no corresponding column in the database table
Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
National all Chinese Automatic Test Software apifox
关于Steam 教育的知识整理
UNET deployment based on deepstream
Cultivate primary and secondary school students' love for educational robots
DC-1靶场搭建及渗透实战详细过程(DC靶场系列)
js面试收藏试题1
正大美欧4的主账户关注什么数据?