原题地址:https://leetcode.cn/problems/shu-ju-liu-zhong-de-zhong-wei-shu-lcof/
题解参考官方题解
我们创建两个优先队列,其中minQue为小于等于中位数的队列(降序),maxQue...
原题地址:https://leetcode.cn/problems/redundant-connection/
题解这道题是一道典型的并查集
我们创建一个dsu的类,包含一个int数组pa,其中pa[i]为节点i的父节点,并规定根节点的父节点为自身...
原题地址:https://leetcode.cn/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/
题解参考题解思路
考虑当数组中只有一个独立元素,其他元素均出现两次时,我们可以很容易地想到...
原题地址:https://leetcode.cn/problems/minimum-moves-to-move-a-box-to-their-target-location/
题解基本思路是两层BFS:对箱子进行BFS搜索,每次判断箱子要移动到一个...
原题地址:https://leetcode.cn/problems/non-overlapping-intervals/
题解参考题解思路
我们将最终版本的区间集合视作一个List或Queue,而我们的目标是:不断地向List中插入符合条件的区间
...
原题地址:https://leetcode.cn/problems/minimum-number-of-arrows-to-burst-balloons/
题解参考题解思路
将集合按照左边界升序排序,然后让箭的位置从左到右扫描,一直扫描到射爆的气球...
原题地址:https://leetcode.cn/problems/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/
题解对于一个节点,我们先求出左子树的链表形态和右子树的链表形态
对于这个节点...
原题地址:https://leetcode.cn/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof/
题解DFS:用递归搜索每个点未搜索的相邻点,每次进入递归时先判断位数和是否有效,无效则直接return
用一...
原题地址:https://leetcode.cn/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof/
题解回溯,每次向List中加入当前节点value,并判断target-val...
原题地址:https://leetcode.cn/problems/number-of-provinces/
题解从一个点开始BFS搜索所有与之相连的城市
对于isConnected[i][i],将其置0表示该城市已被算入一个省份中
对于一个被算...