Description
Given an array of integers nums sorted in ascending 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.
My Solution
class Solution:
def searchRange(self, nums: List[int], target: int) -> List[int]:
from bisect import bisect_left, bisect_right
if target not in nums:
return [-1, -1]
else:
return[bisect_left(nums, target), bisect_right(nums, target)-1]
문제 출처 : https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/
'Algorithm > Daily Coding Tests Challenge' 카테고리의 다른 글
[Leetcode] Easy : Pascal's Triangle (0) | 2021.10.10 |
---|---|
[Leetcode] Easy: Climbing Stairs (0) | 2021.10.10 |
[Leetcode] Hard : Median of Two Sorted Array (0) | 2021.10.09 |
[Leetcode] Medium : Search in Rotated Sorted Array (0) | 2021.10.09 |
[Leetcode] Easy: Valid Anagram (0) | 2021.09.15 |