leetcode 4:Median of Two Sorted Arrays
public double FindMedianSortedArrays(int[] nums1, int[] nums2) {
int t=nums1.Length+nums2.Length;
			int mid1=0;
			int mid2=0;
			int i=0;
			int p1=0;
			int p2=0;
			while(p1<nums1.Length&&p2<nums2.Length&&i<=(t/2))
			{
				if(nums1[p1]<nums2[p2])
				{
					mid1=mid2;
					mid2=nums1[p1];
					p1++;
				}
				else
				{
					mid1=mid2;
					mid2=nums2[p2];
					p2++;
				}
				i++;
			}
			if(i<=(t/2))
			{
				while(p1<nums1.Length&&i<=(t/2))
				{
						mid1=mid2;
						mid2=nums1[p1];
						p1++;
						i++;
				}
				while(p2<nums2.Length&&i<=(t/2))
				{
						mid1=mid2;
						mid2=nums2[p2];
						p2++;
						i++;
				}
			}
			if(t%2==0)
				return (mid1+mid2)/2.0;
			else
				return mid2;
		}
合并两个有序数组,取中间的两个或者一个数
leetcode 4:Median of Two Sorted Arrays的更多相关文章
- leetcode第四题:Median of Two Sorted Arrays   (java)
		Median of Two Sorted Arrays There are two sorted arrays A and B of size m and n respectively. Find t ... 
- No.004:Median of Two Sorted Arrays
		问题: There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the ... 
- 【LeetCode OJ】Median of Two Sorted Arrays
		题目链接:https://leetcode.com/problems/median-of-two-sorted-arrays/ 题目:There are two sorted arrays nums1 ... 
- Leetcode Array 4  Median of Two Sorted Arrays
		做leetcode题目的第二天,我是按照分类来做的,做的第一类是Array类,碰见的第二道题目,也就是今天做的这个,题目难度为hard.题目不难理解,但是要求到了时间复杂度,就需要好好考虑使用一下算法 ... 
- LeetCode2: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 sor ... 
- 【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 t ... 
- 【LeetCode】4. Median of Two Sorted Arrays (2 solutions)
		Median of Two Sorted Arrays There are two sorted arrays A and B of size m and n respectively. Find t ... 
- 《LeetBook》leetcode题解(4): Median of Two Sorted Arrays[H]——两个有序数组中值问题
		我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ... 
- 【LeetCode】004. Median of Two Sorted Arrays
		题目: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ... 
随机推荐
- Android为TV端助力 布局、绘制、内存泄露、响应速度、listview和bitmap、线程优化以及一些优化的建议!
			1.布局优化 首先删除布局中无用的控件和层级,其次有选择地使用性能较低的viewgroup,比如布局中既可以使用RelativeLayout和LinearLayout,那我们就采用LinearLayo ... 
- Kotlin的参考资料
			参考资料和站点 http://kotlinlang.org/ 官方网站 https://github.com/JetBrains/kotlin/releases/tag/v1.0.6 下载compil ... 
- MySQL 安装及卸载详细教程
			本文采用最新版MySQL8版本作为安装教程演示,本人亲试过程,准确无误.可供读者参考. 下载 官网下载 --> 社区免费服务版下载. 下载Windows安装程序MySQL Installer M ... 
- SQL 删除外键列
			一 SQL删除列的语句是: alter table tableName drop column columnName --(其中,tableName为表名,columnName为列名) 但是,如果某列 ... 
- 【audio】耳机插拔 线控按键识别流程【转】
			耳机插拔/线控按键识别流程 耳机插拔/线控按键识别流程 1.文档概述 本文以msm8909平台,android N为例,介绍了通用情况下,耳机插拔的流程步骤,以及对耳机类型的识别逻辑.以方便在项目工作 ... 
- c/c++ 智能指针 weak_ptr 使用
			智能指针 weak_ptr 使用 weak_ptr用途: 1,解决空悬指针问题 2,解决循环引用问题 weak_ptr特点:没有*操作和->操作 weak_ptr是不控制所指对象生存周期的智能指 ... 
- Debian9安装vim和vim无法右键鼠标粘贴解决方法
			问题描述: Debian9有时候安装的时候没有vim,在centos用习惯了vim 1.Debian安装vim: root@kvm1:/etc/network# apt-get install vim ... 
- 【算法】LeetCode算法题-Palindrome Number
			这是悦乐书的第144次更新,第146篇原创 今天这道题和回文有关,即从前往后和从后往前是一样的,如"上海自来水来自海上"就是一个回文字符串,如整数121就是回文数,这些都是和回文相 ... 
- JDK动态代理和cglib代理详解
			JDK动态代理 先做一下简单的描述,通过代理之后返回的对象已并非原类所new出来的对象,而是代理对象.JDK的动态代理是基于接口的,也就是说,被代理类必须实现一个或多个接口.主要原因是JDK的代理原理 ... 
- python3编写网络爬虫23-分布式爬虫
			一.分布式爬虫 前面我们了解Scrapy爬虫框架的基本用法 这些框架都是在同一台主机运行的 爬取效率有限 如果多台主机协同爬取 爬取效率必然成倍增长这就是分布式爬虫的优势 1. 分布式爬虫基本原理 1 ... 
