Leetcode-cn.com 2021-12-05
🟡 372.super-pow
🏷️ Tags
#math #divide_and_conquer
Description
你的任务是计算
Example
🟡 372.super-pow
🏷️ Tags
#math #divide_and_conquer
Description
你的任务是计算
ab 对 1337 取模,a 是一个正整数,b 是一个非常大的正整数且会以数组形式给出。Example
输入:a = 2, b = [3]
输出:8
Leetcode-cn.com 2022-07-15
🟡 558.logical-or-of-two-binary-grids-represented-as-quad-trees
🏷️ Tags
#tree #divide_and_conquer
Description
二进制矩阵中的所有元素不是 0 就是 1 。
给你两个四叉树,
请你返回一个表示
注意,当
四叉树数据结构中,每个内部节点只有四个子节点。此外,每个节点都有两个属性:
我们可以按以下步骤为二维区域构建四叉树:
如果当前网格的值相同(即,全为
如果当前网格的值不同,将
使用适当的子网格递归每个子节点。
如果你想了解更多关于四叉树的内容,可以参考 wiki 。
四叉树格式:
输出为使用层序遍历后四叉树的序列化形式,其中
它与二叉树的序列化非常相似。唯一的区别是节点以列表形式表示
如果
Example
🟡 558.logical-or-of-two-binary-grids-represented-as-quad-trees
🏷️ Tags
#tree #divide_and_conquer
Description
二进制矩阵中的所有元素不是 0 就是 1 。
给你两个四叉树,
quadTree1 和 quadTree2。其中 quadTree1 表示一个 n * n 二进制矩阵,而 quadTree2 表示另一个 n * n 二进制矩阵。请你返回一个表示
n * n 二进制矩阵的四叉树,它是 quadTree1 和 quadTree2 所表示的两个二进制矩阵进行 按位逻辑或运算 的结果。注意,当
isLeaf 为 False 时,你可以把 True 或者 False 赋值给节点,两种值都会被判题机制 接受 。四叉树数据结构中,每个内部节点只有四个子节点。此外,每个节点都有两个属性:
val:储存叶子结点所代表的区域的值。1 对应 True,0 对应 False;isLeaf: 当这个节点是一个叶子结点时为 True,如果它有 4 个子节点则为 False 。
class Node {
public boolean val;
public boolean isLeaf;
public Node topLeft;
public Node topRight;
public Node bottomLeft;
public Node bottomRight;
}
我们可以按以下步骤为二维区域构建四叉树:
如果当前网格的值相同(即,全为
0 或者全为 1),将 isLeaf 设为 True ,将 val 设为网格相应的值,并将四个子节点都设为 Null 然后停止。如果当前网格的值不同,将
isLeaf 设为 False, 将 val 设为任意值,然后如下图所示,将当前网格划分为四个子网格。使用适当的子网格递归每个子节点。
如果你想了解更多关于四叉树的内容,可以参考 wiki 。
四叉树格式:
输出为使用层序遍历后四叉树的序列化形式,其中
null 表示路径终止符,其下面不存在节点。它与二叉树的序列化非常相似。唯一的区别是节点以列表形式表示
[isLeaf, val] 。如果
isLeaf 或者 val 的值为 True ,则表示它在列表 [isLeaf, val] 中的值为 1 ;如果 isLeaf 或者 val 的值为 False ,则表示值为 0 。Example
输入:quadTree1 = [[0,1],[1,1],[1,1],[1,0],[1,0]]
, quadTree2 = [[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]
输出:[[0,0],[1,1],[1,1],[1,1],[1,0]]
解释:quadTree1 和 quadTree2 如上所示。由四叉树所表示的二进制矩阵也已经给出。
如果我们对这两个矩阵进行按位逻辑或运算,则可以得到下面的二进制矩阵,由一个作为结果的四叉树表示。
注意,我们展示的二进制矩阵仅仅是为了更好地说明题意,你无需构造二进制矩阵来获得结果四叉树。
108.convert-sorted-array-to-binary-search-tree.pdf
103.1 KB
leetcode.com 2022-08-10
🟢108.convert-sorted-array-to-binary-search-tree
🏷️ Tags
#array #divide_and_conquer #tree #binary_search_tree #binary_tree
🟢108.convert-sorted-array-to-binary-search-tree
🏷️ Tags
#array #divide_and_conquer #tree #binary_search_tree #binary_tree
654.maximum-binary-tree.pdf
113.3 KB
leetcode.cn 2022-08-20
🟡654.maximum-binary-tree
🏷️ Tags
#stack #tree #array #divide_and_conquer #binary_tree #monotonic_stack
🟡654.maximum-binary-tree
🏷️ Tags
#stack #tree #array #divide_and_conquer #binary_tree #monotonic_stack
218.the-skyline-problem.pdf
210.7 KB
leetcode.com 2022-09-30
🔴218.the-skyline-problem
🏷️ Tags
#array #divide_and_conquer #binary_indexed_tree #segment_tree #line_sweep #heap_priority_queue #ordered_set
🔴218.the-skyline-problem
🏷️ Tags
#array #divide_and_conquer #binary_indexed_tree #segment_tree #line_sweep #heap_priority_queue #ordered_set
918.maximum-sum-circular-subarray.pdf
77 KB
leetcode.com 2023-01-18
🟡918.maximum-sum-circular-subarray
🏷️ Tags
#array #divide_and_conquer #dynamic_programming #queue #monotonic_queue
🟡918.maximum-sum-circular-subarray
🏷️ Tags
#array #divide_and_conquer #dynamic_programming #queue #monotonic_queue
912.sort-an-array.pdf
58.9 KB
leetcode.com 2023-03-01
🟡912.sort-an-array
🏷️ Tags
#array #divide_and_conquer #sorting #heap_priority_queue #merge_sort #bucket_sort #radix_sort #counting_sort
🟡912.sort-an-array
🏷️ Tags
#array #divide_and_conquer #sorting #heap_priority_queue #merge_sort #bucket_sort #radix_sort #counting_sort
109.convert-sorted-list-to-binary-search-tree.pdf
106.1 KB
leetcode.com 2023-03-11
🟡109.convert-sorted-list-to-binary-search-tree
🏷️ Tags
#linked_list #divide_and_conquer #tree #binary_search_tree #binary_tree
🟡109.convert-sorted-list-to-binary-search-tree
🏷️ Tags
#linked_list #divide_and_conquer #tree #binary_search_tree #binary_tree
23.merge-k-sorted-lists.pdf
66.1 KB
leetcode.com 2023-03-12
🔴23.merge-k-sorted-lists
🏷️ Tags
#linked_list #divide_and_conquer #heap_priority_queue #merge_sort
🔴23.merge-k-sorted-lists
🏷️ Tags
#linked_list #divide_and_conquer #heap_priority_queue #merge_sort
106_construct_binary_tree_from_inorder_and_postorder_traversal.pdf
71.3 KB
leetcode.com 2023-03-16
🟡106.construct-binary-tree-from-inorder-and-postorder-traversal
🏷️ Tags
#array #hash_table #divide_and_conquer #tree #binary_tree
🟡106.construct-binary-tree-from-inorder-and-postorder-traversal
🏷️ Tags
#array #hash_table #divide_and_conquer #tree #binary_tree
leetcode.com 2023-05-22
🟡347.top-k-frequent-elements
🏷️ Tags
#array #hash_table #divide_and_conquer #bucket_sort #counting #quickselect #sorting #heap_priority_queue
🟡347.top-k-frequent-elements
🏷️ Tags
#array #hash_table #divide_and_conquer #bucket_sort #counting #quickselect #sorting #heap_priority_queue
Telegraph
top-k-frequent-elements
Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input: nums = [1], k = 1 Output: [1] Constraints:
leetcode.com 2023-06-16
🔴1569.number-of-ways-to-reorder-array-to-get-same-bst
🏷️ Tags
#tree #union_find #binary_search_tree #memoization #array #math #divide_and_conquer #dynamic_programming #binary_tree #combinatorics
🔴1569.number-of-ways-to-reorder-array-to-get-same-bst
🏷️ Tags
#tree #union_find #binary_search_tree #memoization #array #math #divide_and_conquer #dynamic_programming #binary_tree #combinatorics
Telegraph
number-of-ways-to-reorder-array-to-get-same-bst
Given an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the elements of nums in order into an initially empty BST. Find the number of different ways to reorder nums so that…
leetcode.cn 2023-07-20
🟡918.maximum-sum-circular-subarray
🏷️ Tags
#queue #array #divide_and_conquer #dynamic_programming #monotonic_queue
🟡918.maximum-sum-circular-subarray
🏷️ Tags
#queue #array #divide_and_conquer #dynamic_programming #monotonic_queue
Telegraph
maximum-sum-circular-subarray
给定一个长度为 n 的环形整数数组 nums ,返回 nums 的非空 子数组 的最大可能和 。 环形数组 意味着数组的末端将会与开头相连呈环状。形式上, nums[i] 的下一个元素是 nums[(i + 1) % n] , nums[i] 的前一个元素是 nums[(i - 1 + n) % n] 。 子数组 最多只能包含固定缓冲区 nums 中的每个元素一次。形式上,对于子数组 nums[i], nums[i + 1], ..., nums[j] ,不存在 i <= k1, k2 <= j 其中 k1…
leetcode.cn 2023-08-12
🔴23.merge-k-sorted-lists
🏷️ Tags
#linked_list #divide_and_conquer #heap_priority_queue #merge_sort
🔴23.merge-k-sorted-lists
🏷️ Tags
#linked_list #divide_and_conquer #heap_priority_queue #merge_sort
Telegraph
merge-k-sorted-lists
给你一个链表数组,每个链表都已经按升序排列。 请你将所有链表合并到一个升序链表中,返回合并后的链表。 示例 1: 输入:lists = [[1,4,5],[1,3,4],[2,6]] 输出:[1,1,2,3,4,4,5,6] 解释:链表数组如下: [ 1->4->5, 1->3->4, 2->6 ] 将它们合并到一个有序链表中得到。 1->1->2->3->4->4->5->6 示例 2: 输入:lists = [] 输出:[] 示例 3: 输入:lists = [[]] 输出:[] 提示: