Skip to content

Commit 29c53b5

Browse files
035_Search_Insert_Position Python 3 Support (qiyuangong#27)
* Update 035_Search_Insert_Position.py for Python 3 support, by @peterhuang1kimo
1 parent 829e7ac commit 29c53b5

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

python/035_Search_Insert_Position.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,21 @@ class Solution:
2323
# return pos
2424

2525
def searchInsert(self, nums, target):
26-
l, r = 0, len(nums) - 1
26+
l, r = int(0), len(nums) - 1
2727
while l < r:
28-
mid = (l + r) / 2
28+
mid = int((l + r) / 2)
2929
if nums[mid] < target:
3030
l = mid + 1
3131
else:
3232
r = mid
3333
if nums[l] < target:
3434
return l + 1
35-
return l
35+
return l
36+
37+
38+
39+
if __name__ == '__main__':
40+
# begin
41+
s = Solution()
42+
print (s.searchInsert([1,3,5,6],5))
43+

0 commit comments

Comments
 (0)