摘要:查找无序数组的中位数,要想时间复杂度为O(n)其实用计数排序就能很方便地实现,在此讨论使用快速排序进行定位的方法。 1、中位数定义 2、算法思想 3、Java代码实现 4、时间复杂度分析 5、附录 中位数一般两种定义: 第一种: 排序后数组的中间位置的值,如果数组的个数是偶数个,则返回排序后数组的第
阅读全文
摘要:首先,与初始状态无关分为几种情况 1、算法复杂度与初始状态无关; 2、元素总比较次数与初始状态无关; 3、元素总移动次数与初始状态无关。 【其实还有一种就是总排序趟数与初始状态无关,由于分析简单,除了快速排序的排序次数(递归深度)与关键字选择(初始状态)有关,还有一个优化后的冒泡排序和后序是否有序有
阅读全文
摘要:用<a>标签做了下载跳转,为什么点一次,servlet会被执行两次? 写了一个最简单的文件下载点击超链接向servlet发送一个请求,然后下载该文件。可是每次该servlet都会被访问两次,不知道是什么情况JSP: Servlet: 还有一个问题:点击超链接后,浏览器弹出了下载窗口,这个时候我点击下
阅读全文
摘要:今天无意发现这样一道题,可以先做做看: 正确答案是BCD。 至于原因有人给出了参考答案: 1、所有的byte,short,char型的值将被提升为int型; 2、如果有一个操作数是long型,计算结果是long型; 3、如果有一个操作数是float型,计算结果是float型; 4、如果有一个操作数是
阅读全文
摘要:题目难度:Medium 题目: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets i
阅读全文
摘要:题目难度:Medium 题目: Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the
阅读全文
摘要:最近项目中需要导出文件,其实导出文件是一个挺简单的事情。但是却遇到了很奇怪的问题。 首先导出到文件需要用到 BufferedWriter。而换行则是通过 bw.newline() 方法,问题将出在 newline() 方法上面。 我们看一下 newline() api: 1 /** 2 * Writ
阅读全文
摘要:题目难度:Medium 题目: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which g
阅读全文
摘要:题目难度:Medium Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that t
阅读全文
摘要:题目难度:hard 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 com
阅读全文
摘要:题目: Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would hav
阅读全文