leetcode 4

Posted 东东就是我

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode 4相关的知识,希望对你有一定的参考价值。

class Solution(object):
    def findMedianSortedArrays(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: float
        """

        num=(len(nums1)+len(nums2))//2
        s=(len(nums1)+len(nums2))%2
        l,r=0,0
        frist=0
        while l+r<=num:
            if l<len(nums1) and r<len(nums2):
                if nums1[l]<nums2[r]:
                    second=frist
                    frist=nums1[l]
                    l+=1
                else:
                    second=frist
                    frist=nums2[r]
                    r+=1
            elif l==len(nums1) and r<len(nums2):
                second = frist
                frist = nums2[r]
                r += 1
            else:
                second = frist
                frist = nums1[l]
                l += 1
        if s==1:
            return frist
        else:
            return  (second+frist)/2

python3 整除保留一位精度
python2 整除只保留整数

以上是关于leetcode 4的主要内容,如果未能解决你的问题,请参考以下文章