当前位置:网站首页>数组 是否存在重复元素
数组 是否存在重复元素
2022-06-10 20:50:00 【Morris_】
数组中是否存在重复元素
Swift
let array: [Int] = [1,1,1,3,3,4,3,2,4,2]
for i in 0..<array.count {
for j in (i+1)..<array.count {
if (array[i] == array[j]) {
print(true)
return
}
}
}
print(false)
函数实现如下
func containsDuplicate(_ nums: [Int]) -> Bool {
for i in 0..<nums.count {
for j in (i+1)..<nums.count {
if (nums[i] == nums[j]) {
return true
}
}
}
return false
}
调试
let array: [Int] = [1,1,1,3,3,4,3,2,4,2]
let duplicate: Bool = containsDuplicate(array)
print(duplicate)
边栏推荐
- An analysis of SQL query optimization principle (900w+ data from 17s to 300ms)
- 旋转菜单3.0
- Before we learn about high-performance computing, let's take a look at its history
- [untitled] broken item
- C language -- 7 operators
- Calculus review 1
- 2022 - 06 - 09 rk817 PMU Battery Temperature Detection
- 【MySQL】常见数据类型总结
- 学IT毕业后该去哪个城市?哪个岗位薪资高?哪些公司待遇好?
- 报错解决Error parsing Mapper XML
猜你喜欢

在模仿学习中进步的智能机器人

C language ---9 first knowledge of macros and pointers
![[1024 ways to play windows azure] 75 Fast cloud database migration seamlessly migrate alicloud RDS SQL server to azure SQL databas](/img/00/798455f2db289e3aaed36981ea1e7c.png)
[1024 ways to play windows azure] 75 Fast cloud database migration seamlessly migrate alicloud RDS SQL server to azure SQL databas

北大青鸟昌平校区:高中学历可以学UI吗?

C language -- 8 familiar keywords
![[nk] 牛客月赛51 F-平均题](/img/b3/c36a0032e606f38fdc2f7c4562713c.png)
[nk] 牛客月赛51 F-平均题

Detailed explanation of Lora module wireless transceiver communication technology

标配双安全气囊,价格屠夫长安Lumin 4.89万起售

ThinkPHP v6.0. X deserialization vulnerability recurrence

In 2021, the average salary will be released, and the IT industry will not be surprised
随机推荐
[NK] question de calcul de 51 g pour le match lunaire Bullock
【MySQL】表的约束
磁盘序列号,磁盘ID,卷序列号的区别
Constructing the implementation strategy of steam education for children
构建幼儿Steam教育实施策略
【MySQL】表数据的增删查改(DML)
JS mobile terminal copy text to clipboard code
SQL第四练:字符串处理函数
Asynchronous, thread pool (completablefuture)
【phpstorm】 No data sources are configured to run this SQL and provide advanced c
初中毕业生,选择中职学校也可以升入高等学府
C language ---2 initial knowledge of data types
【MySQL】錶數據的增删查改(DML)
Tableau auto - fabriqué
19 MySQL optimizations commonly used in projects
Are you still writing the TS type code
[nk] Niuke monthly competition 51 f-average question
Shaping teenagers' comprehension ability with children's programming thinking
Has the samesite cookie problem occurred when using identityserver?
Acl2022 | bert2bert: an efficient pre training method of parameter reuse, which significantly reduces the training cost of oversized models