53-I.在排序数组中查找数字
Last updated
Last updated
func search(_ nums: [Int], _ target: Int) -> Int {
guard
let first = nums.firstIndex(of: target),
let last = nums.lastIndex(of: target)
else {
return 0
}
return last - first + 1
}