leetcode.com 2023-11-30
🔴1611.minimum-one-bit-operations-to-make-integers-zero
🏷️ Tags
#bit_manipulation #memoization #dynamic_programming
🔴1611.minimum-one-bit-operations-to-make-integers-zero
🏷️ Tags
#bit_manipulation #memoization #dynamic_programming
Telegraph
minimum-one-bit-operations-to-make-integers-zero
Given an integer n, you must transform it into 0 using the following operations any number of times:
leetcode.cn 2023-12-02
🟡1094.car-pooling
🏷️ Tags
#array #prefix_sum #sorting #simulation #heap_priority_queue
🟡1094.car-pooling
🏷️ Tags
#array #prefix_sum #sorting #simulation #heap_priority_queue
Telegraph
car-pooling
车上最初有 capacity 个空座位。车 只能 向一个方向行驶(也就是说,不允许掉头或改变方向) 给定整数 capacity 和一个数组 trips , trip[i] = [numPassengersi, fromi, toi] 表示第 i 次旅行有 numPassengersi 乘客,接他们和放他们的位置分别是 fromi 和 toi 。这些位置是从汽车的初始位置向东的公里数。 当且仅当你可以在所有给定的行程中接送所有乘客时,返回 true,否则请返回 false。 示例 1: 输入:trips…
leetcode.com 2023-12-02
🟢1160.find-words-that-can-be-formed-by-characters
🏷️ Tags
#array #hash_table #string
🟢1160.find-words-that-can-be-formed-by-characters
🏷️ Tags
#array #hash_table #string
Telegraph
find-words-that-can-be-formed-by-characters
You are given an array of strings words and a string chars. A string is good if it can be formed by characters from chars (each character can only be used once). Return the sum of lengths of all good strings in words. Example 1: Input: words = ["cat","bt"…
leetcode.cn 2023-12-03
🟡1423.maximum-points-you-can-obtain-from-cards
🏷️ Tags
#array #prefix_sum #sliding_window
🟡1423.maximum-points-you-can-obtain-from-cards
🏷️ Tags
#array #prefix_sum #sliding_window
Telegraph
maximum-points-you-can-obtain-from-cards
几张卡牌 排成一行,每张卡牌都有一个对应的点数。点数由整数数组 cardPoints 给出。 每次行动,你可以从行的开头或者末尾拿一张卡牌,最终你必须正好拿 k 张卡牌。 你的点数就是你拿到手中的所有卡牌的点数之和。 给你一个整数数组 cardPoints 和整数 k,请你返回可以获得的最大点数。 示例 1: 输入:cardPoints = [1,2,3,4,5,6,1], k = 3 输出:12 解释:第一次行动,不管拿哪张牌,你的点数总是 1 。但是,先拿最右边的卡牌将会最大化你的可获得点数。最…
leetcode.cn 2023-12-04
🟡1038.binary-search-tree-to-greater-sum-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
🟡1038.binary-search-tree-to-greater-sum-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
Telegraph
binary-search-tree-to-greater-sum-tree
给定一个二叉搜索树 root (BST),请将它的每个节点的值替换成树中大于或者等于该节点值的所有节点值之和。 提醒一下, 二叉搜索树 满足下列约束条件:
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: