leetcode
duomiger
这个作者很懒,什么都没留下…
展开
-
leetcode435备注
我看见许多题解都说,需要将右侧的端点按照大小排序,并优先保留右端点更小的区间的存在,删去右端点较大的端点。为什么要这样做呢?很多题解没有给出解答。 原因是这样的:首先,将右端点从小到大进行排序。我们首先考察前两个区间的情况。 情况一:最理想的情况,线一和线二互不重叠,无需考虑删除。 情况二:也是一种很简单的情况。线二比线一覆盖的范围更广,能和线一重叠的,一定也会和线二重叠,所以优先删除线二。 情况三:这种情况比较复杂,需要引入对其他线段的考察。线一和线二部分重叠,但是并没有包含关系。 假设线三是除了.原创 2021-06-01 16:54:43 · 111 阅读 · 1 评论 -
c++ 引用
#include <algorithm> #include <iostream> #include <vector> #include <cmath> using namespace std; void swap1(int a,int b) { int p = a; a = b; b = p; } void swap2(int *a, int *b) { int p = *a; *a = *b; *b = p原创 2021-05-30 20:37:00 · 87 阅读 · 0 评论 -
c++ max_element
#include <algorithm> #include <iostream> #include <vector> #include <cmath> static bool abs_compare(int a, int b) { return (std::abs(a) < std::abs(b)); } int main() { std::vector<int> v{ 3, 1, -14, 1, 5, 9 };原创 2021-05-30 10:51:52 · 312 阅读 · 0 评论 -
leetcode(2)
1、始终觉得学习leetcode太慢,现在开始改变方法,用背题的方法先初步建立思路 同样的题多来几种解法,想必可以加深理解。 1、解法1使用python的特殊函数 class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type ta...原创 2019-12-23 00:07:06 · 90 阅读 · 0 评论 -
leetcode学习(1)
1、这个题 1、python的类中,函数必须有一个参数self,我现在对他的理解还不到位,但是反正知道它不是关键字,但是必须有; 2、python里面的range是【开始,结束,步长】; 3、cpp中,vector是容器; 容器的用法如下图所示 class Solution { public: vector<int>//这个是说声明一个函数,函数类型是vector《int》,是...原创 2019-12-19 20:42:59 · 108 阅读 · 0 评论