34. Find First and Last Position of Element in Sorted Array
34. Find First and Last Position of Element in Sorted Array Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value. If target is not found in the array, return [-1, -1]. You must write an algorithm with O(log n) runtime complexity. 規則 尋找已排序過的陣列找到 first 和 last target 數 測試案例 Example 1: Input: nums = [5,7,7,8,8,10], target = 8 Output: [3,4] Example 2: Input: nums = [5,7,7,8,8,10], target = 6 Output: [-1,-1] Example 3: Input: nums = [], target = 0 Output: [-1,-1] 思路 透過已排序過的輸入,透過二元搜尋法切割查找 找到 first 和 last,回傳 index 如果沒找到則回傳 -1 實作 nums = [1, 3, 3, 5, 7, 8, 9, 9, 9, 15] target = 9 print(Solution()....