1、合并两个有序数组
class Solution(object):
def merge(self
, nums1
, m
, nums2
, n
):
"""
:type nums1: List[int]
:type m: int
:type nums2: List[int]
:type n: int
:rtype: None Do not return anything, modify nums1 in-place instead.
"""
nums1
[:] = sorted(nums1
[:m
] + nums2
)
2、第一个错误的版本
class Solution(object):
def firstBadVersion(self
, n
):
"""
:type n: int
:rtype: int
"""
left
= 1
right
= n
while left
<= right
:
midpoint
= (left
+right
) // 2
if not isBadVersion
(midpoint
):
left
= midpoint
+ 1
else:
right
= midpoint
- 1
return left
转载请注明原文地址:https://tech.qufami.com/read-19732.html