Open
Description
public func checkIfExist(_ arr: [Int]) -> Bool {
guard !arr.isEmpty else { return false }
var set: Set<Int> = []
for i in 0..<arr.count {
if set.contains(arr[i] * 2) || (arr[i] % 2 == 0 && set.contains(arr[i] / 2)) {
// If either the double or half of the current element exists in the set, return true
return true
}
set.insert(arr[i])
}
// for i in 0..<arr.count {
// let num = 2*arr[i]
// results.insert(num)
// }
// for value in arr {
// if results.contains(value) {
// return true
// }
// }
return false
}
Metadata
Metadata
Assignees
Labels
No labels