class Solution {
public:
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2){
vector<int> nums;
if (nums1.size() > nums2.size()){
nums = nums1;
for (unsigned int i = ; i < nums2.size(); ++i){
nums.push_back(nums2[i]);
}
}
else{
nums = nums2;
for (unsigned int i = ; i < nums1.size(); ++i){
nums.push_back(nums1[i]);
}
}
sort(nums.begin(), nums.end());
if (nums.size() & true){
return nums[nums.size() / ];
}
else{
return (nums[nums.size() / ] + nums[(nums.size() / ) - ]) / 2.0;
}
}
};

看起来很难,但其实原理很简单。

leetcode 第4题 Median of Two Sorted Arrays的更多相关文章

  1. LeetCode 第四题 Median of Two Sorted Arrays 二人 渣渣选手乱七八糟分析发现基本回到思路1

    题目 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...

  2. leetcode第二题--Median of Two Sorted Arrays

    Problem:There are two sorted arrays A and B of size m and n respectively. Find the median of the two ...

  3. 【LeetCode】4、Median of Two Sorted Arrays

    题目等级:Hard 题目描述:   There are two sorted arrays nums1 and nums2 of size m and n respectively.   Find t ...

  4. LeetCode(4)Median of Two Sorted Arrays

    题目 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...

  5. LeetCode解题笔记 - 4. Median of Two Sorted Arrays

    There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...

  6. LeetCode 笔记系列一 Median of Two Sorted Arrays

    题目:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sort ...

  7. LeetCode 4 Median of Two Sorted Arrays (两个数组的mid值)

    题目来源:https://leetcode.com/problems/median-of-two-sorted-arrays/ There are two sorted arrays nums1 an ...

  8. 【转载】两个排序数组的中位数 / 第K大元素(Median of Two Sorted Arrays)

    转自 http://blog.csdn.net/zxzxy1988/article/details/8587244 给定两个已经排序好的数组(可能为空),找到两者所有元素中第k大的元素.另外一种更加具 ...

  9. 4. Median of Two Sorted Arrays(topK-logk)

    4. Median of Two Sorted Arrays 题目 There are two sorted arrays nums1 and nums2 of size m and n respec ...

随机推荐

  1. 浅谈UML中常用的几种图——用例图

    1.UML简介 统一建模语言(Unified Modeling Language,UML)又称标准建模语言,是始于1997年的一个OMG标准,它是一个支持模型化和软件系统开发的图形化语言,为软件开发的 ...

  2. PHP以xml形式获取POST数据

    <?php namespace Home\Controller; use Think\Controller; class UrlController extends Controller { / ...

  3. Oracle启用和禁用触发器

    1.禁用 table_name 表的所有 trigger alter table table_name disable all triggers; 2.启用 table_name 表的所有 trigg ...

  4. python----数据驱动@ddt.file_data结合yaml文件的使用

    一.创建yaml文件1. 安装yaml模块 pip install pyyaml2. 新建yaml文件 右键任意文件夹-->New-->File,输入文件名并以.yaml或.yml结尾 二 ...

  5. 常见排序算法JAVA实现

    1.冒泡排序,时间复杂度:最好:T(n) = O(n) ,情况:T(n) = O(n2) ,平均:T(n) = O(n2) public int[] bubbleSort(int[] nums) { ...

  6. 移动端根据dpr适配

    'use strict'; /** * @param {Number} [baseFontSize = 100] - 基础fontSize, 默认100px; * @param {Number} [f ...

  7. 二分查找方法和printk打印级别

    人生就是一个茶几,上面摆满了杯具.内核也是一个大茶几,不过它上面的杯具是一个个的bug.确定bug什么时候被引入是一个很关键的步骤,在这个定位bug的过程中,不论有意或无意,都会很自然地用到二分查找的 ...

  8. week4_1

    ---恢复内容开始--- _________________________________列表生成式_____________________ a = [a*2 for a in range(10) ...

  9. hdu2132

    题目:We once did a lot of recursional problem . I think some of them is easy for you and some if hard ...

  10. Freeswitch 各版本一键安装脚本 Freeswitch 快速安装 G729编解码库

    最近有时间整理,写了freeswitch的一键安装包分享一下,里面带有 mysql=0 是否选择安装mysql. 其他提示:脚本里面集成了安装g729脚本,支持录音.转码的bcg729脚本. 1.下载 ...