Movatterモバイル変換


[0]ホーム

URL:


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

Commitfa0fe95

Browse files
authored
Update 3-35. Search Insert Position
1 parentccf7573 commitfa0fe95

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

‎3-35. Search Insert Position

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ class Solution:
2525
else:
2626
return mid + 1
2727

28-
try to optimize a bit more, check the flow once again see if you reduce some lines
29-
check solutions on youtube as well
28+
try to optimize a bit more, check the flow once again see if you reduce some lines
29+
check solutions on youtube as well
3030

31+
Algorithm1 repeat
32+
Solution 2:
33+
34+
def searchInsert(self, nums: List[int], target: int) -> int:
35+
l = 0
36+
r = len(nums)
37+
38+
while l < r:
39+
mid = (l + r) // 2
40+
if nums[mid] == target:
41+
return mid
42+
elif nums[mid] < target:
43+
l = mid + 1
44+
else:
45+
r = mid
46+
47+
return l

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp