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. 20165309 《网络对抗技术》实验一:PC平台逆向破解

    20165309 <网络对抗技术>实验一:PC平台逆向破解 目录 实践目标 基础知识 实验原理.内容及步骤 问题与解决 实验收获 一.实践目标 本次实践的对象是一个名为pwn1的linux ...

  2. leetcode-979-树

    https://leetcode.com/problems/distribute-coins-in-binary-tree/ n个硬币随机分布在n个点上,要求每个点都拥有一个硬币,问最小的花费. 对每 ...

  3. vue-quill-editor富文本编辑器,上传图片自定义为借口上传

    vue-quill-editor富文本编辑器,上传图片自定义为借口上传 博客地址:https://blog.csdn.net/lyj2018gyq/article/details/82585194

  4. WORDPRESS博客完美更换网站空间服务器的方法

    更换主机空间的步骤:原主机的所有数据移动至新主机上→修改wp-config.php数据库连接信息 (1)备份原主机全站文件 使用FTP备份网站根目录下所有文件并上传到新主机,向主机客服询问FTP地址. ...

  5. ZedBoard前期准备工作

    1. 资源下载 内核:https://github.com/Xilinx/linux-xlnx/releases uboot:https://github.com/Xilinx/u-boot-xlnx ...

  6. 八大排序算法——希尔(shell)排序(动图演示 思路分析 实例代码java 复杂度分析)

    一.动图演示 二.思路分析 希尔排序是把记录按下标的一定增量分组,对每组使用直接插入排序算法排序:随着增量逐渐减少,每组包含的关键词越来越多,当增量减至1时,整个文件恰被分成一组,算法便终止. 简单插 ...

  7. 运用Python计算Π的多少(大致计算)

    计算Π 一.写代码的准备工作:用pip下载第三方库tqdm 1.打开cmd 2.输入pip install   你要安装的库(如 pip install tqdm)   #pip一般是在安装pytho ...

  8. 深入理解hashCode

    1.hashCode的概念 (1)hashCode方法是Object类的方法,在Java里所有类都默认继承Object类,即所有类都有hashCode方法. (2)hashCode是jdk根据对象的存 ...

  9. 如何练习打字之用英文写文章 & 如何调养右手之用左手握鼠标

    part1:how to practise your typing via writing a English blog it's easy to write english for chinese. ...

  10. gat和post封装代码

    from urllib import request, parsefrom urllib.error import HTTPError, URLError def get(url, headers=N ...