LeetCode#4 Median of Two Sorted Arrays
来源:互联网 发布:landmark软件介绍 编辑:程序博客网 时间:2024/05/16 09:17
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
class Solution: # @param {integer[]} nums1 # @param {integer[]} nums2 # @return {float} def findMedianSortedArrays(self, nums1, nums2): i = 0 j = 0 k = 0 newArr = [] while i < len(nums1) and j < len(nums2): if nums1[i]<=nums2[j]: newArr.append(nums1[i]) i+=1 k+=1 else: newArr.append(nums2[j]) j+=1 k+=1 while i < len(nums1): newArr.append(nums1[i]) i+=1 k+=1 while j < len(nums2): newArr.append(nums2[j]) j+=1 k+=1 num = len(nums1) + len(nums2) if num % 2 == 1: return newArr[num/2] else: return float(newArr[num/2-1]+newArr[num/2])/2
0 0
- Leetcode 4 Median of Two Sorted Arrays
- LeetCode 4 - Median of Two Sorted Arrays
- Leetcode 4 Median of Two Sorted Arrays
- Leetcode 4 Median of Two Sorted Arrays
- [leetcode 4] Median of Two Sorted Arrays
- LeetCode 4:《Median of Two Sorted Arrays》
- [Leetcode] 4 - Median of Two Sorted Arrays
- leetcode|4|Median of Two Sorted Arrays
- [Leetcode]4Median of Two Sorted Arrays
- leetcode 4 Median of Two Sorted Arrays
- LeetCode #4 Median of Two Sorted Arrays
- LeetCode-4-Median of Two Sorted Arrays
- LeetCode 4 Median of Two Sorted Arrays
- leetcode 4 Median of Two Sorted Arrays
- LeetCode 4 Median of Two Sorted Arrays
- Leetcode[4] Median of Two Sorted Arrays
- LeetCode 4 - Median of Two Sorted Arrays
- leetcode 4 -- Median of Two Sorted Arrays
- 让餐厅放心的云服务-雅座CRM技术解密
- 专访4秒源码商城CTO陈杰:扎根互联网的“不安的心”
- 批处理使用简要说明
- STM32W108无线ZigBee射频模块
- STM32W108无线射频模块通用IO接口
- LeetCode#4 Median of Two Sorted Arrays
- IOC介绍及其简单实现
- java对redis的基本操作
- 如何用几何作图法构造阿基米德双子圆
- opencv之纹理特征(熵值)的提取
- FaceNet--Google的人脸识别
- Deep Learning Face Representation by Joint Identification-Verification
- 算法 乐趣 程序
- 求M的N次方的最后三位