004Median of Two Sorted Arrays (C)
来源:互联网 发布:扫地机器人算法 编辑:程序博客网 时间:2024/06/06 10:00
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)).
double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size) { double add[nums1Size+nums2Size];int k=0,i,j;for(i=0,j=0;i<nums1Size&&j<nums2Size;){if(nums1[i]<=nums2[j]){add[k]=nums1[i];i++;k++;}else{add[k]=nums2[j];j++;k++;}}if(i<nums1Size){while(i<nums1Size){add[k]=nums1[i];k++;i++;}}if(j<nums2Size){while(j<nums2Size){add[k]=nums2[j];k++;j++;}}i=0;j=k-1;while(j-i>1){i++;j--;}if(i==j){ return add[i];}else{ return (add[i]+add[j])/2.0;}}
0 0
- 004Median of Two Sorted Arrays (C)
- leetcode Median of Two Sorted Arrays (C)
- 4. Median of Two Sorted Arrays(C++)
- leetcode-004:Median of Two Sorted Arrays
- [LeetCode]-004-Median of Two Sorted Arrays
- 004Median of Two Sorted Arrays
- 004 Median of Two Sorted Arrays [Leetcode]
- 004 - Median of Two Sorted Arrays
- [LeetCode]004-Median of Two Sorted Arrays
- Leetcode 004 Median of Two Sorted Arrays
- LeetCode 004 Median of Two Sorted Arrays *
- leetcode-004 Median of Two Sorted Arrays
- LeetCode 004 Median of Two Sorted Arrays
- 004 Median of Two Sorted Arrays ⭐
- LeetCode-004 Median of Two Sorted Arrays
- leetcode 004 Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- File and Print Services for Microsoft® Windows® Clients (Samba)
- if eles 问题
- 遍历map效率最高的方法
- 添加xib 子控件约束
- 个人总结3
- 004Median of Two Sorted Arrays (C)
- Git 解决Bug:fatal: Could not read from remote repository ——诺诺"涂鸦"记忆
- 设计模式-组合模式
- 3.大神班 scrollView 与 动画 imageView的加载图片
- iOS强弱引用宏
- 手把手教你使用Git--初学者的好福利
- 通往全栈工程师的捷径 —— react
- Masonry教程--IOS自适配
- Web开发&文件上传下载及编码解码