##  已知l1,l2均为升序数组,
##  在两数组l1,l2中寻找第n位数,
##  两数组中位数中,前者大于后者,说明后者中位数以下的成员必定在真正中位数之下
##  可以将其剔除,剔除a个元素后的两数组中寻找第n-a位数,等价于
def findmid(l1,l2):
    m,n=len(l1),len(l2)
    if (m+n)%2==0:
        return  (listrec(l1,l2,(m+n)/2)+listrec(l1,l2,(m+n)/2))/2
    else:
        return listrec(l1,l2,(m+n+1)/2)
## la长度大于等于lb
def listrec(la,lb,i):
    m,n=len(la),len(lb)
    if n==0:
        return la[i-1]
    if m<n:
        return listrec(lb,la,i)
    if i==1:
        return min(la[0],lb[0])
    p=min(int(i/2),n)
    print(m,n,i,p)
    if la[p-1]>lb[-1]:
        return listrec(la,lb[p:],i-p)
    else:
        return listrec(la[p:],lb,i-p)

lm=[x for x in range(13,200)if x%2==0]
ln=[x for x in range(15,99)if x%2==1]
print(findmid(lm,ln))

leetcode python 004的更多相关文章

  1. Leetcode Python Solution(continue update)

    leetcode python solution 1. two sum (easy) Given an array of integers, return indices of the two num ...

  2. LeetCode python实现题解(持续更新)

    目录 LeetCode Python实现算法简介 0001 两数之和 0002 两数相加 0003 无重复字符的最长子串 0004 寻找两个有序数组的中位数 0005 最长回文子串 0006 Z字型变 ...

  3. [LeetCode][Python]Container With Most Water

    # -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/container-with-most-water/ Given n non-neg ...

  4. LeetCode Python 位操作 1

    Python 位操作: 按位与 &, 按位或 | 体会不到 按位异或 ^ num ^ num = 0 左移 << num << 1 == num * 2**1 右移 & ...

  5. 【leetcode❤python】Sum Of Two Number

    #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...

  6. [Leetcode][Python]56: Merge Intervals

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 56: Merge Intervalshttps://oj.leetcode. ...

  7. [Leetcode][Python]55: Jump Game

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 55: Jump Gamehttps://leetcode.com/probl ...

  8. [Leetcode][Python]54: Spiral Matrix

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 54: Spiral Matrixhttps://leetcode.com/p ...

  9. [Leetcode][Python]53: Maximum Subarray

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 53: Maximum Subarrayhttps://leetcode.co ...

随机推荐

  1. 用basicTrendline画一元线性回归直线的置信区间

    感慨统计学都还给老师了..恶补! R安装包的时候貌似需要用管理员权限启动,否则安装不了,国内镜像卡得渣渣,还是国外镜像真香~选择hongkong就好了. install.packages(" ...

  2. Go语言学习之7 接口实例、终端文件读写、异常处理

    本节主要内容: 1. 终端读写2. 文件读写3. 命令行参数4. Json5. 自定义错误 1. 终端读写 操作终端相关文件句柄常量    os.Stdin:标准输入    os.Stdout:标准输 ...

  3. Notepad++ 的资源管理器 右键菜单

    以前装的版本,右键[Edit With Notepad++]都可以出来的. 最近安装的总是不行. 不知道是Windows的原因,还是新版本的原因. 网上也都是用workaround去解决的. 免费的东 ...

  4. Getting started with Processing 第十一章——数组

    Getting started with Processing 第十一章——数组 从变量到数组: 使用数组,无需为每一个变量创建一个新的名称/这让代码变得更短,更容易理解,更方便更新. 创建数组的三个 ...

  5. spring cloud ----> RibbonClient设置的熔断器Hystrix不起作用

    Ribbon spring.io 官网的简介: Ribbon is a client side load balancer which gives you a lot of control over ...

  6. LeetCode--020--括号匹配

    题目描述: 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. 注意空 ...

  7. p1530 Fractions to Decimals

    将余数记录下来,如果余数相同,那么商的下一位也相同. #include <iostream> #include <cstdio> #include <cmath> ...

  8. 廖雪峰网站:学习python函数—定义函数(二)

    def my_abs(x): if x >= 0: return x else: return -x print(my_abs(-99)) # 空函数 def nop(): pass # 参数检 ...

  9. 5月30---6月2 DedeCMS以及动态仿站

    什么是DedeCMS 织梦内容管理系统(DedeCMS),是一个集内容发布.编辑.管理检索等于一体的网站管理系统(Web CMS),他拥有国外CMS众多特点之外,还结合中国用户的需要,对内容管理系统概 ...

  10. 根据userAgent判断打开网页的所在终端,以及浏览器

    function _IsIOS() { var ua = navigator.userAgent.toLowerCase(); if(ua.match(/iPhone\sOS/i) == " ...