一二三四五 上山打老虎

上一页 1 2 3 4 5 6 ··· 15 下一页
摘要: 链接:https://leetcode-cn.com/problems/find-eventual-safe-states/ 题意:如果在环上或者能到达再环上的点则不满足题意,否则输出。 方法一:DFS+染色 判环: 0:未访问过 1:在环上或者在递归的过程中 2:不在环上也不到环 代码: clas 阅读全文
posted @ 2021-08-05 21:43 abestxun 阅读(40) 评论(0) 推荐(0) 编辑
摘要: 题意:对于[1:n](n<=1e18)构造一个最小的数列,使得数列中的任意个数的相加能得到[1:n]所有的数,且数列中数只可用一次,比如n=6时,最小数列是{1,2,4}: 方法:对于数值相加可以发现规律: {1,2}->{1,2,3} n=[3] {1,2,4}->{1,2,3,4,5,6,7} 阅读全文
posted @ 2021-07-29 22:13 abestxun 阅读(31) 评论(0) 推荐(0) 编辑
摘要: 1.题目:203. 移除链表元素 链接:https://leetcode-cn.com/problems/remove-linked-list-elements/ 方法1:递归:递归函数定义为当前节点所指向的链表中无node.val==v的情况 class Solution { public: Li 阅读全文
posted @ 2021-07-20 19:15 abestxun 阅读(27) 评论(0) 推荐(0) 编辑
摘要: 运算符: 1:& 取地址运算符,&a运算结果是一个指针,指针的类型是a的类型前加*,指针所指向的类型是a的类型, &a所指向的地址是a的地址。 2:* 间接运算符,p为指针,*p类型是p所指向的类型,占用的地址也是p所指向的地址 例如: int a=10; int * b=&a; *b=10; b为 阅读全文
posted @ 2021-07-20 17:18 abestxun 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 链接:https://leetcode-cn.com/problems/wiggle-subsequence/ 思路:DP有分两种状态来考虑:当前是上升的状态能构成的子序列长度,当前是下降的状态构成子序列长度 可以滚动数组优化为两个元素来表示 代码: class Solution { public: 阅读全文
posted @ 2021-07-18 21:54 abestxun 阅读(78) 评论(0) 推荐(0) 编辑
摘要: 链接:https://leetcode-cn.com/problems/group-anagrams-lcci/ 思路: 对string排序后作为键值,map嵌套vector数组 万物皆可map,万物皆可sort class Solution { public: vector<vector<stri 阅读全文
posted @ 2021-07-18 10:29 abestxun 阅读(32) 评论(0) 推荐(0) 编辑
摘要: C++11后引入emplace_back函数 emplace_back原理:在容器尾部添加一个元素,元素原地构造,不需要拷贝构造和转移构造。 push_back原理:首先调用构造函数创造对应插入值的临时对象,然后调用拷贝构造函数将这个临时变量放入容器中,原来的临时变量释放。 使用emplace_ba 阅读全文
posted @ 2021-07-18 10:25 abestxun 阅读(316) 评论(0) 推荐(0) 编辑
摘要: 链接:https://leetcode-cn.com/problems/the-skyline-problem/ 218. 天际线问题 代码: class Solution { public: vector<vector<int>> getSkyline(vector<vector<int>>& b 阅读全文
posted @ 2021-07-13 11:38 abestxun 阅读(54) 评论(0) 推荐(0) 编辑
摘要: 链接:https://leetcode-cn.com/problems/minimum-cost-to-reach-destination-in-time/ 思路: 方法1.f[i][j]表示第i时间到达j位置所需要的费用,状态转移方程是:f[i][y]=min(f[i][y],f[i-e[x][y 阅读全文
posted @ 2021-07-11 10:29 abestxun 阅读(82) 评论(0) 推荐(0) 编辑
摘要: 链接:https://leetcode-cn.com/problems/count-good-meals/ 1711. 大餐计数 题意:一个长度为1e5的数组,计算有多少对数字可以组成2的次方,结果对1e9+7取余,数组最大值为2e20 思路:根据题意,组成的2的次方num范围为[0,2e40],只 阅读全文
posted @ 2021-07-07 21:59 abestxun 阅读(51) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 15 下一页