
二分
xiaocong1990
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
[leetcode]kth-smallest-element-in-a-sorted-matrix 有序矩阵中第k小元素
【代码】[leetcode]kth-smallest-element-in-a-sorted-matrix 有序矩阵中第k小元素。原创 2024-07-10 16:21:20 · 412 阅读 · 0 评论 -
[LeetCode] H-Index II
Given an array of citationssortedin ascending order(each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According to thedefinition of h...原创 2020-04-11 16:48:35 · 226 阅读 · 1 评论 -
[leetcode] smallest-k-lcci. 最小的k个数
【代码】[leetcode] smallest-k-lcci. 最小的k个数。原创 2024-06-26 17:12:35 · 247 阅读 · 0 评论 -
[leetcode]search-insert-position 搜索插入位置
【代码】[leetcode]search-insert-position 搜索插入位置。原创 2024-06-26 14:48:51 · 222 阅读 · 0 评论 -
[leetcode]valid-triangle-number. 有效三角形的个数
【代码】[leetcode]valid-triangle-number. 有效三角形的个数。原创 2024-06-25 21:44:45 · 206 阅读 · 0 评论 -
[leetcode]234. Palindrome Linked List
题目链接 :https://leetcode.com/problems/palindrome-linked-list/Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?class原创 2016-11-14 08:49:36 · 229 阅读 · 1 评论 -
[leetcode]leetcode 162. 寻找峰值(优质解法)
当 nums[i]>nums[i+1]时,i 下标的左边肯定存在一个峰值,因为最左边是 - ∞ ,所以必定需要经历递增,再在 i 这里经历递减,所以必定存在一个峰值,但 i 的右边,可能不会存在峰值,因为可以直接递减到 - ∞,所以我们可以大胆的去除掉 i 右边的数据(i 下标指向的数据不能去除,因为我们不确定 i 是否就是要找的峰值)当 nums[i] < nums[i+1]时,i 下标的右边肯定存在一个峰值,但 i 的左边,可能不会存在峰值,所以我们可以大胆的去除掉 i 左边的数据和 i 的值。原创 2024-06-07 18:49:15 · 157 阅读 · 0 评论 -
[leetcode]小数平方根
【代码】[leetcode]小数平方根。原创 2024-05-16 20:43:47 · 311 阅读 · 0 评论 -
[leetcode]在排序数组中查找元素中的第一个和最后一个位置
请你找出给定目标值在数组中的开始位置和结束位置。给你一个按照非递减顺序排列的整数数组。你必须设计并实现时间复杂度为。如果数组中不存在目标值。原创 2024-05-02 19:51:58 · 160 阅读 · 0 评论 -
[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 · 211 阅读 · 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 · 923 阅读 · 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 · 291 阅读 · 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 · 366 阅读 · 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 · 329 阅读 · 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 · 393 阅读 · 0 评论 -
[lintcode]74. 第一个错误的代码版本
链接:https://www.lintcode.com/zh-cn/problem/first-bad-version/代码库的版本号是从 1 到 n 的整数。某一天,有人提交了错误版本的代码,因此造成自身及之后版本的代码在单元测试中均出错。请找出第一个错误的版本号。你可以通过 isBadVersion 的接口来判断版本号 version 是否在单元测试中出错,具体原创 2018-04-26 19:53:34 · 330 阅读 · 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 · 308 阅读 · 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 · 217 阅读 · 0 评论 -
[lintcode]824. 落单的数 IV
链接:https://www.lintcode.com/problem/single-number-iv/description描述给定数组,除了一个数出现一次外,所有数都出现两次,并且所有出现两次的数都挨着。请找出找出那个出现一次的数。1 为了约束程序的时间复杂度,你的程序将会运行 10^5 次您在真实的面试中是否遇到过这个题?原创 2018-05-05 17:33:50 · 306 阅读 · 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 · 278 阅读 · 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 · 177 阅读 · 0 评论 -
[leetcode]4. Median of Two Sorted Arrays. 寻找两个正序数组的中位数
链接:https://leetcode.com/problems/median-of-two-sorted-arrays/description/There are two sorted arraysnums1andnums2of size m and n respectively.Find the median of the two sorted arrays. The over...原创 2018-10-27 20:07:39 · 257 阅读 · 1 评论 -
[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 · 266 阅读 · 1 评论 -
最近点对
算法: 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 · 609 阅读 · 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 · 287 阅读 · 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 · 250 阅读 · 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 · 212 阅读 · 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 · 265 阅读 · 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 · 431 阅读 · 0 评论 -
[leetcode]18. 4Sum
题目链接:https://leetcode.com/problems/4sum/#/descriptionGiven an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the原创 2017-05-17 12:26:17 · 311 阅读 · 1 评论 -
[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 · 484 阅读 · 1 评论 -
[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 · 232 阅读 · 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 · 359 阅读 · 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 · 316 阅读 · 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 · 391 阅读 · 0 评论 -
[网易]分田地
题目描述牛牛和 15个朋友来玩打土豪分田地的游戏,牛牛决定让你来分田地,地主的田地可以看成是一个矩形,每个位置有一个价值。分割田地的方法是横竖各切三刀,分成 16份,作为领导干部,牛牛总是会选择其中总价值最小的一份田地, 作为牛牛最好的朋友,你希望牛牛取得的田地的价值和尽可能大,你知道这个值最大可以是多少吗?输入描述:每个输入包含 1 个测试用例。每个测试用例的第一行包原创 2018-04-03 16:07:12 · 396 阅读 · 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 · 333 阅读 · 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 · 413 阅读 · 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 · 338 阅读 · 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 · 249 阅读 · 0 评论