![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
二分
wonderabd
这个作者很懒,什么都没留下…
展开
-
[LeetCode]16. 最接近的三数之和
时间复杂度O(n²logn) 先排序,再枚举前两个数,二分找可能产生最佳答案的第三个数,尝试更新答案。 16. 最接近的三数之和 class Solution { public: int threeSumClosest(vector<int>& nums, int target) { int tip=nums.size(); int a[...原创 2019-04-07 22:48:53 · 84 阅读 · 0 评论 -
[LeetCode]15. 三数之和
相似题:16.最接近的三数之和 只需要注意一些细节,“答案中不可以包含重复的三元组”。 遇到重复出现的数就continue。 15. 三数之和 class Solution { public: vector<vector<int>> threeSum(vector<int>& nums) { int target=0; ...原创 2019-04-07 23:19:50 · 68 阅读 · 0 评论 -
[LeetCode]274. H指数+275. H指数 II
先排序。 从小到大找到第一个i,满足n-i>=citations[i-1] && n-i<=citations[i](n指数组长度) 274. H指数 class Solution { public: int hIndex(vector<int>& citations) { int n=citations.size(); ...原创 2019-05-02 13:27:57 · 243 阅读 · 0 评论 -
[leetcode]374.猜数字大小
题目描述:我们正在玩一个猜数字游戏。 游戏规则如下: 我从 1 到 n 选择一个数字。 你需要猜我选择了哪个数字。 每次你猜错了,我会告诉你这个数字是大了还是小了。 你调用一个预先定义好的接口 guess(int num),它会返回 3 个可能的结果(-1,1 或 0): -1 : 我的数字比较小 1 : 我的数字比较大 0 : 恭喜!你猜对了! 题目链接:374.猜数字大小 就是二分…… /...原创 2019-05-15 16:15:08 · 218 阅读 · 0 评论 -
[LeetCode]300. 最长上升子序列
题目描述:给定一个无序的整数数组,找到其中最长上升子序列的长度。 题目链接:300. 最长上升子序列 nlogn求最长上升子序列 记录每个长度的上升子序列的 "结尾"的最小值 class Solution { public: int lengthOfLIS(vector<int>& nums) { int tot=0; int x...原创 2019-05-16 21:29:00 · 83 阅读 · 0 评论