##  已知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. python 读写TXT,安装pandas模块。

    今天需要用python读TXT 文件,发现pandas库好用,所以就去下载,没想pythoncharm中的setting中下载失败,所以去下源文件,安装pandas 是提示得先装numpy库,于是又去 ...

  2. 关于在使用sparksql写程序是报错以及解决方案:org.apache.spark.sql.AnalysisException: Duplicate column(s): "name" found, cannot save to file.

    说明: spark --version : 2.2.0 我有两个json文件,分别是emp和dept: emp内容如下: {"name": "zhangsan" ...

  3. English trip M1 - AC11 I Dreamed a Dream? 我做了一个梦 Teacher:Lamb

    In this lesson you will learn to describe an experience.  这节课你讲学习到描述经历 课上内容(Lesson) 词汇(Key Word ) 句型 ...

  4. 20180518VSTO多簿单表汇总

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsof ...

  5. android--------内存泄露分析工具—Android Monitor

    Android Studio 内置了四种性能监测工具Memory Monitor.Network Monitor.CPU Monitor.GPU Monitor,我们可以使用这些工具监测APP的状态, ...

  6. mysql之filesort原理

    在执行计划中,可能经常看到有Extra列有filesort,这就是使用了文件排序,这当然是不好的,应该优化,但是,了解一下他排序的原理也许很有帮助,下面看一下filesort的过程: 1.根据表的索引 ...

  7. http bass

    1.http 是超文本传输协议,是从万维网服务器传输超文本到本地浏览器的传输协议 2.http是一个基于tcp/ip通信协议来传输数据(html,图片,查询结果等) 3.一个完整的http请求包含7个 ...

  8. SSM框架中各层作用

    SSM是sping+springMVC+mybatis集成的框架. MVC即model view controller. model层=entity层.存放我们的实体类,与数据库中的属性值基本保持一致 ...

  9. DBWritable的使用

    首先导入mysql连接驱动jar包 或者maven模式下在pom.xml文件中追加: <dependency> <groupId>mysql</groupId> & ...

  10. lombok @EqualsAndHashCode 注解的影响

    官方文档:@EqualsAndHashCode 原文中提到的大致有以下几点: 1. 此注解会生成equals(Object other) 和 hashCode()方法. 2. 它默认使用非静态,非瞬态 ...