
二分法
永远的EMT
每天时刻保持超越自我的意识
展开
-
【LeetCode】4. Median of Two Sorted Arrays
题解:二分法,先转化为第k大的数,每次查找过滤掉k/2大的部分double findMedianSortedArrays(vector& nums1, vector& nums2) { int len1=nums1.size(); int len2=nums2.size(); int len= len1+len2; if(len%2){ re原创 2017-07-25 23:52:12 · 274 阅读 · 0 评论 -
【LeetCode】Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right. The first integer of each row...原创 2018-11-06 23:54:01 · 160 阅读 · 0 评论 -
【LeetCode】Search a 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in each...原创 2018-11-07 00:00:08 · 210 阅读 · 0 评论 -
【LeetCode】4. 寻找两个有序数组的中位数
给定两个大小为 m 和 n 的有序数组nums1 和nums2。 请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为O(log(m + n))。 你可以假设nums1和nums2不会同时为空。 示例 1: nums1 = [1, 3] nums2 = [2] 则中位数是 2.0 示例 2: nums1 = [1, 2] nums2 = [3, 4] 则中位数是...原创 2019-06-15 18:49:08 · 321 阅读 · 0 评论 -
【LeetCode】410. 分割数组的最大值
给定一个非负整数数组和一个整数m,你需要将这个数组分成m个非空的连续子数组。设计一个算法使得这m个子数组各自和的最大值最小。 注意: 数组长度n满足以下条件: 1 ≤ n ≤ 1000 1 ≤ m ≤ min(50, n) 示例: 输入: nums = [7,2,5,10,8] m = 2 输出: 18 解释: 一共有四种方法将nums分割为2个子数组。 其中最好的方式是...原创 2019-06-30 22:42:39 · 444 阅读 · 0 评论 -
【LeetCode】378. Kth Smallest Element in a Sorted Matrix
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not ...原创 2019-06-30 23:24:32 · 176 阅读 · 0 评论