(k 表示 positions 的长度) 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/number-of-islands-ii著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 2. 解题 参考数据结构:并查集(Disjoint-Set) 2.1 超时解 125 / 162 个通过测试用例 将矩阵的每个位置看成并查集中的一个点,...
// https://leetcode.cn/problems/find-nearest-right-node-in-binary-tree/description/ // 1602. 找到二叉树中最近的右侧节点 #include<iostream> #include<queue> using namespace std; struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode() : val(0), left(nullptr), right(null...
https://leetcode.com/problems/data-stream-as-disjoint-intervals/ Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen so far as a list of disjoint intervals. For example, suppose the integers from the data stream are 1, 3, 7, 2, 6...
LeetCode1234https://leetcode.com/problems/replace-the-substring-for-balanced-string/ LeetCode1248https://leetcode.com/problems/count-number-of-nice-subarrays/ LeetCode1461https://leetcode.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k/ LeetCode1521https://leetcode.com/prob...
547,https://leetcode.com/problems/friend-circles/ Sets are called as Disjoint if their union is equal to universal set. Perhaps rewording this is a good idea... Being disjoint is a property of a pair of sets. Maybe you mean: "A DSU represents a collection as a collection o...
Provide all my solutions and explanations in Chinese for all the Leetcode coding problems. Same as this: LeetCode All in One 题目讲解汇总(持续更新中...) Click below image to watch YouTube Video Note: All explanations are written in Github Issues, please do not create any new issue or ...
The first part is the solutions to some classic problems on LeetCode, including the idea thinkings, key points and code implementations. The second part is a summary of data structures and algorithms. The third part is Anki flashcards that organizes the LeetCode problems in a certain way to...
Java union-find(disjoint set) solution with explanation. publicclassMinCostToConnectAllNodes{// represent dis-joint set using an arrayprivateint[] parent;privateintconnectionLength;privatevoidunion(intv1,intv2){// check if both vertices are descendants of same parent i.e. they belong to same ...
// Solution 1: Union-find set. 代码1 //Code 1 306 Additive Number // #306 加性数 描述:斐波那契数列知道吧?现在给定这么一个数列,开头俩数可以不是1,把这个数列连成一个数,我们称其为“加性数”。现在给定一个数,判断是不是加性数。
Problems List in there String Problems List in there Two Pointers 双指针滑动窗口的经典写法。右指针不断往右移,移动到不能往右移动为止(具体条件根据题目而定)。当右指针到最右边以后,开始挪动左指针,释放窗口左边界。第 3 题,第 76 题,第 209 题,第 424 题,第 438 题,第 567 题,第 713 题,第 763...