leetcode.cn 2023-12-05
🟡2477.minimum-fuel-cost-to-report-to-the-capital
🏷️ Tags
#tree #depth_first_search #breadth_first_search #graph
🟡2477.minimum-fuel-cost-to-report-to-the-capital
🏷️ Tags
#tree #depth_first_search #breadth_first_search #graph
Telegraph
minimum-fuel-cost-to-report-to-the-capital
给你一棵 n 个节点的树(一个无向、连通、无环图),每个节点表示一个城市,编号从 0 到 n - 1 ,且恰好有 n - 1 条路。0 是首都。给你一个二维整数数组 roads ,其中 roads[i] = [ai, bi] ,表示城市 ai 和 bi 之间有一条 双向路 。 每个城市里有一个代表,他们都要去首都参加一个会议。 每座城市里有一辆车。给你一个整数 seats 表示每辆车里面座位的数目。 城市里的代表可以选择乘坐所在城市的车,或者乘坐其他城市的车。相邻城市之间一辆车的油耗是一升汽油。 请你返回到达首都最少需要多少升汽油。…
❤1
leetcode.cn 2023-12-06
🔴2646.minimize-the-total-price-of-the-trips
🏷️ Tags
#tree #depth_first_search #graph #array #dynamic_programming
🔴2646.minimize-the-total-price-of-the-trips
🏷️ Tags
#tree #depth_first_search #graph #array #dynamic_programming
Telegraph
minimize-the-total-price-of-the-trips
现有一棵无向、无根的树,树中有 n 个节点,按从 0 到 n - 1 编号。给你一个整数 n 和一个长度为 n - 1 的二维整数数组 edges ,其中 edges[i] = [ai, bi] 表示树中节点 ai 和 bi 之间存在一条边。 每个节点都关联一个价格。给你一个整数数组 price ,其中 price[i] 是第 i 个节点的价格。 给定路径的 价格总和 是该路径上所有节点的价格之和。 另给你一个二维整数数组 trips ,其中 trips[i] = [starti, endi] 表示您从节点…
leetcode.cn 2023-12-07
🟡1466.reorder-routes-to-make-all-paths-lead-to-the-city-zero
🏷️ Tags
#depth_first_search #breadth_first_search #graph
🟡1466.reorder-routes-to-make-all-paths-lead-to-the-city-zero
🏷️ Tags
#depth_first_search #breadth_first_search #graph
Telegraph
reorder-routes-to-make-all-paths-lead-to-the-city-zero
n 座城市,从 0 到 n-1 编号,其间共有 n-1 条路线。因此,要想在两座不同城市之间旅行只有唯一一条路线可供选择(路线网形成一颗树)。去年,交通运输部决定重新规划路线,以改变交通拥堵的状况。 路线用 connections 表示,其中 connections[i] = [a, b] 表示从城市 a 到 b 的一条有向路线。 今年,城市 0 将会举办一场大型比赛,很多游客都想前往城市 0 。 请你帮助重新规划路线方向,使每个城市都可以访问城市 0 。返回需要变更方向的最小路线数。 题目数据 保证 …
leetcode.cn 2023-12-08
🟡2008.maximum-earnings-from-taxi
🏷️ Tags
#array #binary_search #dynamic_programming #sorting
🟡2008.maximum-earnings-from-taxi
🏷️ Tags
#array #binary_search #dynamic_programming #sorting
Telegraph
maximum-earnings-from-taxi
你驾驶出租车行驶在一条有 n 个地点的路上。这 n 个地点从近到远编号为 1 到 n ,你想要从 1 开到 n ,通过接乘客订单盈利。你只能沿着编号递增的方向前进,不能改变方向。 乘客信息用一个下标从 0 开始的二维数组 rides 表示,其中 rides[i] = [starti, endi, tipi] 表示第 i 位乘客需要从地点 starti 前往 endi ,愿意支付 tipi 元的小费。 每一位 你选择接单的乘客 i ,你可以 盈利 endi - starti + tipi 元。你同时 最多 只能接一个订单。…
leetcode.com 2023-12-08
🟢606.construct-string-from-binary-tree
🏷️ Tags
#tree #depth_first_search #string #binary_tree
🟢606.construct-string-from-binary-tree
🏷️ Tags
#tree #depth_first_search #string #binary_tree
Telegraph
construct-string-from-binary-tree
Given the root of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal way, and return it. Omit all the empty parenthesis pairs that do not affect the one-to-one mapping relationship between…
leetcode.cn 2023-12-09
🟡2048.next-greater-numerically-balanced-number
🏷️ Tags
#math #backtracking #enumeration
🟡2048.next-greater-numerically-balanced-number
🏷️ Tags
#math #backtracking #enumeration
Telegraph
next-greater-numerically-balanced-number
如果整数 x 满足:对于每个数位 d ,这个数位 恰好 在 x 中出现 d 次。那么整数 x 就是一个 数值平衡数 。 给你一个整数 n ,请你返回 严格大于 n 的 最小数值平衡数 。 示例 1: 输入:n = 1 输出:22 解释: 22 是一个数值平衡数,因为: - 数字 2 出现 2 次 这也是严格大于 1 的最小数值平衡数。 示例 2: 输入:n = 1000 输出:1333 解释: 1333 是一个数值平衡数,因为: - 数字 1 出现 1 次。 - 数字 3 出现 3 次。 这也是严格大于…
leetcode.com 2023-12-09
🟢94.binary-tree-inorder-traversal
🏷️ Tags
#stack #tree #depth_first_search #binary_tree
🟢94.binary-tree-inorder-traversal
🏷️ Tags
#stack #tree #depth_first_search #binary_tree
Telegraph
binary-tree-inorder-traversal
Given the root of a binary tree, return the inorder traversal of its nodes' values. Example 1: Input: root = [1,null,2,3] Output: [1,3,2] Example 2: Input: root = [] Output: [] Example 3: Input: root = [1] Output: [1] Constraints:
leetcode.cn 2023-12-11
🟡1631.path-with-minimum-effort
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #binary_search #matrix #heap_priority_queue
🟡1631.path-with-minimum-effort
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #binary_search #matrix #heap_priority_queue
Telegraph
path-with-minimum-effort
你准备参加一场远足活动。给你一个二维 rows x columns 的地图 heights ,其中 heights[row][col] 表示格子 (row, col) 的高度。一开始你在最左上角的格子 (0, 0) ,且你希望去最右下角的格子 (rows-1, columns-1) (注意下标从 0 开始编号)。你每次可以往 上,下,左,右 四个方向之一移动,你想要找到耗费 体力 最小的一条路径。 一条路径耗费的 体力值 是路径上相邻格子之间 高度差绝对值 的 最大值 决定的。 请你返回从左上角走到右下角的最小 体力消耗值 。…
leetcode.com 2023-12-12
🟢1464.maximum-product-of-two-elements-in-an-array
🏷️ Tags
#array #sorting #heap_priority_queue
🟢1464.maximum-product-of-two-elements-in-an-array
🏷️ Tags
#array #sorting #heap_priority_queue
Telegraph
maximum-product-of-two-elements-in-an-array
Example 1: Input: nums = [3,4,5,2] Output: 12 Explanation: If you choose the indices i=1 and j=2 (indexed from 0), you will get the maximum value, that is, (nums[1]-1)*(nums[2]-1) = (4-1)*(5-1) = 3*4 = 12. Example 2: Input: nums = [1,5,4,5] Output: 16 Explanation:…
leetcode.cn 2023-12-13
🟢2697.lexicographically-smallest-palindrome
🏷️ Tags
#greedy #two_pointers #string
🟢2697.lexicographically-smallest-palindrome
🏷️ Tags
#greedy #two_pointers #string
Telegraph
lexicographically-smallest-palindrome
给你一个由 小写英文字母 组成的字符串 s ,你可以对其执行一些操作。在一步操作中,你可以用其他小写英文字母 替换 s 中的一个字符。 请你执行 尽可能少的操作 ,使 s 变成一个 回文串 。如果执行 最少 操作次数的方案不止一种,则只需选取 字典序最小 的方案。 对于两个长度相同的字符串 a 和 b ,在 a 和 b 出现不同的第一个位置,如果该位置上 a 中对应字母比 b 中对应字母在字母表中出现顺序更早,则认为 a 的字典序比 b 的字典序要小。 返回最终的回文字符串。 示例 1: 输入:s…