二分
xiaocong1990
这个作者很懒,什么都没留下…
展开
-
[leetcode]50. Pow(x, n)
题目链接:https://leetcode.com/problems/powx-n/#/descriptionImplement pow(x,n).class Solution {public: double myPow(double x, int n) { if (n == 0) return 1.0; el原创 2017-05-12 18:04:05 · 169 阅读 · 0 评论 -
[leetcode]数组中的逆序对
链接力扣在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对。输入一个数组,求出这个数组中的逆序对的总数。示例 1:输入: [7,5,6,4]输出: 5来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。方法一:归并排序预备知识「归并排序」是分治思想的典型应用,它包含.原创 2022-01-10 23:16:17 · 293 阅读 · 0 评论 -
[leetcode]81. Search in Rotated Sorted Array II
题目链接:https://leetcode.com/problems/search-in-rotated-sorted-array-ii/#/descriptionFollow upfor "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexit...原创 2017-05-28 11:48:35 · 362 阅读 · 0 评论 -
[lintcode]98. 链表排序
链接:http://www.lintcode.com/zh-cn/problem/sort-list/在 O(n log n) 时间复杂度和常数级的空间复杂度下给链表排序。您在真实的面试中是否遇到过这个题? Yes样例给出 1->3->2->null,给它排序变成 1->2->3->null.思路:对链原创 2018-04-08 19:01:37 · 285 阅读 · 0 评论 -
[网易]分田地
题目描述牛牛和 15个朋友来玩打土豪分田地的游戏,牛牛决定让你来分田地,地主的田地可以看成是一个矩形,每个位置有一个价值。分割田地的方法是横竖各切三刀,分成 16份,作为领导干部,牛牛总是会选择其中总价值最小的一份田地, 作为牛牛最好的朋友,你希望牛牛取得的田地的价值和尽可能大,你知道这个值最大可以是多少吗?输入描述:每个输入包含 1 个测试用例。每个测试用例的第一行包原创 2018-04-03 16:07:12 · 327 阅读 · 0 评论 -
最近点对
算法: 0:把所有的点按照横坐标排序 1:用一条竖直的线L将所有的点分成两等份 2:递归算出左半部分的最近两点距离d1,右半部分的最近两点距离d2,取d=min(d1,d2) 3:算出“一个在左半部分,另一个在右半部分”这样的点对的最短距离d3。 4:结果=min(d1,d2,d3) 关键就是这第3步。貌似这需要n^2的时间原创 2018-04-06 18:21:44 · 544 阅读 · 0 评论 -
[lintcode]141. x的平方根
链接:https://www.lintcode.com/zh-cn/problem/sqrtx/实现int sqrt(int x)函数,计算并返回x的平方根。您在真实的面试中是否遇到过这个题?Yes样例sqrt(3) = 1sqrt(4) = 2sqrt(5) = 2sqrt(10) = 3cla原创 2018-04-23 13:48:34 · 197 阅读 · 0 评论 -
[lintcode]248. 统计比给定整数小的数的个数
链接:https://www.lintcode.com/zh-cn/problem/count-of-smaller-number/给定一个整数数组 (下标由 0 到 n-1,其中 n 表示数组的规模,数值范围由 0 到 10000),以及一个 查询列表。对于每一个查询,将会给你一个整数,请你返回该数组中小于给定整数的元素的数量。 注意事项在做此题前,最好先完成原创 2018-05-03 21:03:23 · 306 阅读 · 0 评论 -
[lintcode]414. 两个整数相除
链接:https://www.lintcode.com/zh-cn/problem/divide-two-integers/将两个整数相除,要求不使用乘法、除法和 mod 运算符。如果溢出,返回 2147483647 。您在真实的面试中是否遇到过这个题? Yes样例给定被除数 = 100 ,除数 = 9,返回 11。原创 2018-05-03 21:20:48 · 273 阅读 · 0 评论 -
[lintcode]428. x的n次幂
链接:https://www.lintcode.com/zh-cn/problem/powx-n/实现 pow(x,n) 注意事项不用担心精度,当答案和标准输出差绝对值小于1e-3时都算正确您在真实的面试中是否遇到过这个题? Yes样例Pow(2.1, 3) = 9.261Pow(0, 1)原创 2018-05-04 16:07:44 · 340 阅读 · 0 评论 -
[lintcode]74. 第一个错误的代码版本
链接:https://www.lintcode.com/zh-cn/problem/first-bad-version/代码库的版本号是从 1 到 n 的整数。某一天,有人提交了错误版本的代码,因此造成自身及之后版本的代码在单元测试中均出错。请找出第一个错误的版本号。你可以通过 isBadVersion 的接口来判断版本号 version 是否在单元测试中出错,具体原创 2018-04-26 19:53:34 · 273 阅读 · 0 评论 -
[leetcode]Find K-th Smallest Pair Distance:查找数组元素中差值第K大的两个元素的差值
链接:https://leetcode.com/problems/find-k-th-smallest-pair-distance/description/Given an integer array, return the k-th smallestdistanceamong all the pairs. The distance of a pair (A, B) is defined as...原创 2018-05-18 10:46:24 · 251 阅读 · 0 评论 -
[leetcode]658. Find K Closest Elements
链接:https://leetcode.com/problems/find-k-closest-elements/description/Given a sorted array, two integerskandx, find thekclosest elements toxin the array. The result should also be原创 2018-05-05 16:01:26 · 166 阅读 · 0 评论 -
[lintcode]824. 落单的数 IV
链接:https://www.lintcode.com/problem/single-number-iv/description描述给定数组,除了一个数出现一次外,所有数都出现两次,并且所有出现两次的数都挨着。请找出找出那个出现一次的数。1 为了约束程序的时间复杂度,你的程序将会运行 10^5 次您在真实的面试中是否遇到过这个题?原创 2018-05-05 17:33:50 · 263 阅读 · 0 评论 -
[leetcode]493. Reverse Pairs
链接:https://leetcode.com/problems/reverse-pairs/description/Given an arraynums, we call(i, j)animportant reverse pairifi < jandnums[i] > 2*nums[j].You need to return the number of importa...原创 2018-06-12 21:09:49 · 209 阅读 · 0 评论 -
[leetcode]4. Median of Two Sorted Arrays
链接:https://leetcode.com/problems/median-of-two-sorted-arrays/description/There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall ...原创 2018-05-30 14:03:52 · 133 阅读 · 0 评论 -
[leetcode]4. Median of Two Sorted Arrays
链接:https://leetcode.com/problems/median-of-two-sorted-arrays/description/There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The over...原创 2018-10-27 20:07:39 · 209 阅读 · 0 评论 -
[leetcode]33. Search in Rotated Sorted Array
题目链接:https://leetcode.com/problems/search-in-rotated-sorted-array/#/descriptionSuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might ...原创 2017-05-28 11:07:14 · 295 阅读 · 0 评论 -
[leetcode]154. Find Minimum in Rotated Sorted Array II
题目链接:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/#/descriptionSuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e.,0原创 2017-06-17 21:03:24 · 212 阅读 · 0 评论 -
[leetcode]287. Find the Duplicate Number
题目链接:https://leetcode.com/problems/find-the-duplicate-number/?tab=DescriptionGiven an arraynumscontainingn+ 1 integers where each integer is between 1 andn(inclusive), prove that at least原创 2017-02-24 22:52:19 · 305 阅读 · 0 评论 -
[leetcode]34. Search for a Range
题目链接:https://leetcode.com/problems/search-for-a-range/#/descriptionGiven an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your al原创 2017-05-16 11:58:03 · 195 阅读 · 0 评论 -
[leetcode]148. Sort List
题目链接:https://leetcode.com/problems/sort-list/#/descriptionSort a linked list inO(nlogn) time using constant space complexity./** * Merge sort use bottom-up policy, * so Space原创 2017-05-17 11:09:02 · 421 阅读 · 0 评论 -
[leetcode]18. 4Sum
题目链接:https://leetcode.com/problems/4sum/#/descriptionGiven 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 in the原创 2017-05-17 12:26:17 · 240 阅读 · 0 评论 -
[leetcode]16. 3Sum Closest
题目链接:https://leetcode.com/problems/3sum-closest/#/descriptionGiven 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 th原创 2017-05-28 10:26:48 · 257 阅读 · 0 评论 -
[leetcode]215. Kth Largest Element in an Array
题目链接:https://leetcode.com/problems/kth-largest-element-in-an-array/#/descriptionFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order原创 2017-03-14 17:26:55 · 368 阅读 · 0 评论 -
[leetcode]153. Find Minimum in Rotated Sorted Array
题目链接:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/#/descriptionSuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1原创 2017-06-17 20:28:33 · 215 阅读 · 0 评论 -
[leetcode]367. Valid Perfect Square
题目链接:https://leetcode.com/problems/valid-perfect-square/#/descriptionGiven a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use原创 2017-07-16 16:03:10 · 174 阅读 · 0 评论 -
[leetcode]352. Data Stream as Disjoint Intervals
题目链接:https://leetcode.com/problems/data-stream-as-disjoint-intervals/description/Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen so far as a原创 2017-08-11 20:04:51 · 212 阅读 · 0 评论 -
[leetcode]483. Smallest Good Base
题目链接:https://leetcode.com/problems/smallest-good-base/description/For an integer n, we call k>=2 a good base of n, if all digits of n base k are 1.Now given a string representing n, you shou原创 2017-08-14 11:56:56 · 251 阅读 · 0 评论 -
[leetcode]315. Count of Smaller Numbers After Self
题目链接:https://leetcode.com/problems/count-of-smaller-numbers-after-self/description/You are given an integer arraynumsand you have to return a newcountsarray. Thecountsarray has the propert原创 2017-08-13 14:37:06 · 283 阅读 · 0 评论 -
[leetcode]327. Count of Range Sum
题目链接:https://leetcode.com/problems/count-of-range-sum/description/Given an integer arraynums, return the number of range sums that lie in[lower, upper]inclusive.Range sumS(i, j)is defin原创 2017-08-24 20:49:50 · 322 阅读 · 0 评论 -
[leetcode]410. Split Array Largest Sum
题目链接:https://leetcode.com/problems/split-array-largest-sum/#/descriptionGiven an array which consists of non-negative integers and an integer m, you can split the array into m non-empty continuo原创 2017-06-27 21:57:39 · 323 阅读 · 0 评论 -
[leetcode]668. Kth Smallest Number in Multiplication Table
题目链接:https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/description/Nearly every one have used theMultiplication Table. But could you find out thek-thsmallest num原创 2017-08-28 18:08:24 · 838 阅读 · 0 评论 -
[leetcode]69. Sqrt(x)
题目链接:https://leetcode.com/problems/sqrtx/#/descriptionImplement int sqrt(int x).Compute and return the square root of x.class Solution {public: int mySqrt(int x) { if(x==0)原创 2017-07-11 11:30:31 · 165 阅读 · 0 评论 -
[leetcode]633. Sum of Square Numbers
题目链接:https://leetcode.com/problems/sum-of-square-numbers/#/descriptionGiven a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c.Exa原创 2017-07-16 20:41:35 · 233 阅读 · 0 评论 -
[leetcode]15. 3Sum
题目链接:https://leetcode.com/problems/3sum/#/descriptionGiven 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 gi原创 2017-05-12 11:15:41 · 233 阅读 · 0 评论