##  已知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. Cisco 设备设置监控口

    > enable                 # 从用户模式进入特权模式# show ip int bri     # 查看当前所有端口状态 # conf t                ...

  3. android-------开发常用框架汇总

    响应式编程 RxJava https://github.com/ReactiveX/RxJava RxAndroid https://github.com/ReactiveX/RxAndroid 消息 ...

  4. 小程序动态添加class及调接口传递多个参数

    1.动态添加class <view class="step2 {{indication == 2 ?'on':''}}"> <view class='tc lef ...

  5. wdcp环境redis的位置

  6. 整体二分求动态区间第k大

    比树状数组套主席树不知道高到哪里去了,solve(l,r,L,R)就是对于L,R的操作区间的答案都在l,r区间里,然后递归下去 复杂度O(nlognlogn),每个操作会执行logn次就是o(nlog ...

  7. 【微信公众号开发】【8】网页授权获取用户基本信息(OAuth 2.0)

    前言: 1,在微信公众号请求用户网页授权之前,开发者需要先到公众平台官网中的“开发 - 接口权限 - 网页服务 - 网页帐号 - 网页授权获取用户基本信息”的配置选项中,修改授权回调域名. 请注意,这 ...

  8. DOM与document的区别

    DOM: DOM 全称是 Document Object Model,也就是文档对象模型. DOM 就是针对 HTML 和 XML 提供的一个API.什么意思?就是说为了能以编程的方法操作这个 HTM ...

  9. 使用LVM方式安装Ubuntu 16.04

    --- By 小甘丶 注: 这里只讲解如何配置LVM,其他不再陈述! 这个方法,通用的!只要操作系统支持LVM即可!(个人推测,尚未证实) 配置好虚拟机后,开始安装,先进入Ubuntu使用界面,对磁盘 ...

  10. TCHAR用法

    TCHAR 就是当你的字符设置为什么就是什么例如:程序编译为 ANSI, TCHAR 就是相当于 CHAR当程序编译为 UNICODE, TCHAR 就相当于 WCHAR char :单字节变量类型, ...