From 01cd6d1f81dfff75e75c42baa96c97303f079ced Mon Sep 17 00:00:00 2001 From: Lebhroryi Date: Fri, 7 Feb 2020 20:34:12 +0800 Subject: [PATCH] =?UTF-8?q?add=20leetcode=2034=20=E4=B8=80=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index d4ef891..c93bfe5 100644 --- a/README.md +++ b/README.md @@ -415,6 +415,19 @@ class Solution: i = (bisect.bisect_left(nums[k:] + nums[:k], target) + k) % max(len(nums), 1) return i if nums and nums[i] == target else -1 ``` + +## [34. 在排序数组中查找元素的第一个和最后一个位置](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) + +- 用自带的bisect函数,一行 + +```python3 +class Solution: + def searchRange(self, nums: List[int], target: int) -> List[int]: + # if not nums or target not in nums: return [-1, -1] + return [bisect.bisect_left(nums, target), bisect.bisect_right(nums, target)-1] \ + if nums and target in nums else [-1, -1] +``` + ## [35. Search Insert Position 1行](https://leetcode.com/problemset/all/?search=35) ```python class Solution:

AltStyle によって変換されたページ (->オリジナル) /