leetcode.cn 2023-05-31
🟡1130.minimum-cost-tree-from-leaf-values
🏷️ Tags
#stack #greedy #array #dynamic_programming #monotonic_stack
🟡1130.minimum-cost-tree-from-leaf-values
🏷️ Tags
#stack #greedy #array #dynamic_programming #monotonic_stack
Telegraph
minimum-cost-tree-from-leaf-values
给你一个正整数数组 arr,考虑所有满足以下条件的二叉树:
leetcode.cn 2023-07-23
🔴42.trapping-rain-water
🏷️ Tags
#stack #array #two_pointers #dynamic_programming #monotonic_stack
🔴42.trapping-rain-water
🏷️ Tags
#stack #array #two_pointers #dynamic_programming #monotonic_stack
Telegraph
trapping-rain-water
给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。 示例 1: 输入:height = [0,1,0,2,1,0,1,3,2,1,2,1] 输出:6 解释:上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图,在这种情况下,可以接 6 个单位的雨水(蓝色部分表示雨水)。 示例 2: 输入:height = [4,2,0,3,2,5] 输出:9 提示:
leetcode.com 2023-09-30
🟡456.132-pattern
🏷️ Tags
#stack #array #binary_search #ordered_set #monotonic_stack
🟡456.132-pattern
🏷️ Tags
#stack #array #binary_search #ordered_set #monotonic_stack
Telegraph
132-pattern
Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j]. Return true if there is a 132 pattern in nums, otherwise, return false. Example 1: Input:…
leetcode.com 2023-10-22
🔴1793.maximum-score-of-a-good-subarray
🏷️ Tags
#stack #array #two_pointers #binary_search #monotonic_stack
🔴1793.maximum-score-of-a-good-subarray
🏷️ Tags
#stack #array #two_pointers #binary_search #monotonic_stack
Telegraph
maximum-score-of-a-good-subarray
You are given an array of integers nums (0-indexed) and an integer k. The score of a subarray (i, j) is defined as min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1). A good subarray is a subarray where i <= k <= j. Return the maximum possible score of a…
leetcode.cn 2023-11-17
🔴2736.maximum-sum-queries
🏷️ Tags
#stack #binary_indexed_tree #segment_tree #array #binary_search #sorting #monotonic_stack
🔴2736.maximum-sum-queries
🏷️ Tags
#stack #binary_indexed_tree #segment_tree #array #binary_search #sorting #monotonic_stack
Telegraph
maximum-sum-queries
给你两个长度为 n 、下标从 0 开始的整数数组 nums1 和 nums2 ,另给你一个下标从 1 开始的二维数组 queries ,其中 queries[i] = [xi, yi] 。 对于第 i 个查询,在所有满足 nums1[j] >= xi 且 nums2[j] >= yi 的下标 j (0 <= j < n) 中,找出 nums1[j] + nums2[j] 的 最大值 ,如果不存在满足条件的 j 则返回 -1 。 返回数组 answer ,其中 answer[i] 是第 i 个查询的答案。…
leetcode.cn 2023-11-27
🟡907.sum-of-subarray-minimums
🏷️ Tags
#stack #array #dynamic_programming #monotonic_stack
🟡907.sum-of-subarray-minimums
🏷️ Tags
#stack #array #dynamic_programming #monotonic_stack
Telegraph
sum-of-subarray-minimums
给定一个整数数组 arr,找到 min(b) 的总和,其中 b 的范围为 arr 的每个(连续)子数组。 由于答案可能很大,因此 返回答案模 10^9 + 7 。 示例 1: 输入:arr = [3,1,2,4] 输出:17 解释:子数组为 [3],[1],[2],[4],[3,1],[1,2],[2,4],[3,1,2],[1,2,4],[3,1,2,4]。 最小值为 3,1,2,4,1,1,2,1,1,1,和为 17。 示例 2: 输入:arr = [11,81,94,43,3] 输出:444 …
leetcode.cn 2024-01-03
🟡2487.remove-nodes-from-linked-list
🏷️ Tags
#stack #recursion #linked_list #monotonic_stack
🟡2487.remove-nodes-from-linked-list
🏷️ Tags
#stack #recursion #linked_list #monotonic_stack
Telegraph
remove-nodes-from-linked-list
给你一个链表的头节点 head 。 移除每个右侧有一个更大数值的节点。 返回修改后链表的头节点 head 。 示例 1: 输入:head = [5,2,13,3,8] 输出:[13,8] 解释:需要移除的节点是 5 ,2 和 3 。 - 节点 13 在节点 5 右侧。 - 节点 13 在节点 2 右侧。 - 节点 8 在节点 3 右侧。 示例 2: 输入:head = [1,1,1,1] 输出:[1,1,1,1] 解释:每个节点的值都是 1 ,所以没有需要移除的节点。 提示:
leetcode.cn 2024-01-05
🔴1944.number-of-visible-people-in-a-queue
🏷️ Tags
#stack #array #monotonic_stack
🔴1944.number-of-visible-people-in-a-queue
🏷️ Tags
#stack #array #monotonic_stack
Telegraph
number-of-visible-people-in-a-queue
有 n 个人排成一个队列,从左到右 编号为 0 到 n - 1 。给你以一个整数数组 heights ,每个整数 互不相同,heights[i] 表示第 i 个人的高度。 一个人能 看到 他右边另一个人的条件是这两人之间的所有人都比他们两人 矮 。更正式的,第 i 个人能看到第 j 个人的条件是 i < j 且 min(heights[i], heights[j]) > max(heights[i+1], heights[i+2], ..., heights[j-1]) 。 请你返回一个长度为 n 的数…