Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 01cd6d1

Browse files
committed
add leetcode 34 一行
1 parent 6721b7f commit 01cd6d1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,19 @@ class Solution:
415415
i = (bisect.bisect_left(nums[k:] + nums[:k], target) + k) % max(len(nums), 1)
416416
return i if nums and nums[i] == target else -1
417417
```
418+
419+
## [34. 在排序数组中查找元素的第一个和最后一个位置](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/)
420+
421+
- 用自带的bisect函数,一行
422+
423+
```python3
424+
class Solution:
425+
def searchRange(self, nums: List[int], target: int) -> List[int]:
426+
# if not nums or target not in nums: return [-1, -1]
427+
return [bisect.bisect_left(nums, target), bisect.bisect_right(nums, target)-1] \
428+
if nums and target in nums else [-1, -1]
429+
```
430+
418431
## [35. Search Insert Position 1行](https://leetcode.com/problemset/all/?search=35)
419432
```python
420433
class Solution:

0 commit comments

Comments
(0)

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