2013年3月4日

[Leetcode] Median of Two Sorted Arrays

摘要: 大致思路:先寻找每个数组的中位数,因为是排好顺序的数组,因此,可以在O(1)时间内找到。然后,比较这两个数字的大小。如果A的中位数大于B的中位数,则在A的前半个数组和B的后半个数组中寻找; 反之,在B的前半个数组和A的后半个数组寻找。根据递归方程,解得时间复杂度是O(lg(n)).A general version:Find the Kth element of two sorted arrays A[] and B[]. 1 #include <cstdio> 2 #include <iostream> 3 #include <cstdlib> 4 usi 阅读全文

posted @ 2013-03-04 23:06 龙豆 阅读(1182) 评论(0) 推荐(0) 编辑

导航