1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-16 16:36:56 +02:00
LeetCode/swift/element-appearing-more-than-25-in-sorted-array.swift
Matej Focko 2351dfd0ee
chore: unwrap one layer
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-12-12 14:36:00 +01:00

22 lines
437 B
Swift

class Solution {
func findSpecialInteger(_ arr: [Int]) -> Int {
let threshold = arr.count / 4
var last = -1
var counter = 0
for x in arr {
if last != x {
counter = 1
last = x
} else {
counter += 1
}
if counter > threshold {
return last
}
}
return -1
}
}