leetcode.cn 2025-05-23
🔴3068.find-the-maximum-sum-of-node-values
🏷️ Tags
#greedy #bit_manipulation #tree #array #dynamic_programming #sorting
🔴3068.find-the-maximum-sum-of-node-values
🏷️ Tags
#greedy #bit_manipulation #tree #array #dynamic_programming #sorting
Telegraph
find-the-maximum-sum-of-node-values
给你一棵 n 个节点的 无向 树,节点从 0 到 n - 1 编号。树以长度为 n - 1 下标从 0 开始的二维整数数组 edges 的形式给你,其中 edges[i] = [ui, vi] 表示树中节点 ui 和 vi 之间有一条边。同时给你一个 正 整数 k 和一个长度为 n 下标从 0 开始的 非负 整数数组 nums ,其中 nums[i] 表示节点 i 的 价值 。 Alice 想 最大化 树中所有节点价值之和。为了实现这一目标,Alice 可以执行以下操作 任意 次(包括 0 次):
leetcode.com 2025-05-23
🔴3068.find-the-maximum-sum-of-node-values
🏷️ Tags
#greedy #bit_manipulation #tree #array #dynamic_programming #sorting
🔴3068.find-the-maximum-sum-of-node-values
🏷️ Tags
#greedy #bit_manipulation #tree #array #dynamic_programming #sorting
Telegraph
find-the-maximum-sum-of-node-values
There exists an undirected tree with n nodes numbered 0 to n - 1. You are given a 0-indexed 2D integer array edges of length n - 1, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree. You are also given a positive…
leetcode.cn 2025-05-25
🟡2131.longest-palindrome-by-concatenating-two-letter-words
🏷️ Tags
#greedy #array #hash_table #string #counting
🟡2131.longest-palindrome-by-concatenating-two-letter-words
🏷️ Tags
#greedy #array #hash_table #string #counting
Telegraph
longest-palindrome-by-concatenating-two-letter-words
给你一个字符串数组 words 。words 中每个元素都是一个包含 两个 小写英文字母的单词。 请你从 words 中选择一些元素并按 任意顺序 连接它们,并得到一个 尽可能长的回文串 。每个元素 至多 只能使用一次。 请你返回你能得到的最长回文串的 长度 。如果没办法得到任何一个回文串,请你返回 0 。 回文串 指的是从前往后和从后往前读一样的字符串。 示例 1: 输入:words = ["lc","cl","gg"] 输出:6 解释:一个最长的回文串为 "lc" + "gg" + "cl" =…
leetcode.com 2025-05-25
🟡2131.longest-palindrome-by-concatenating-two-letter-words
🏷️ Tags
#greedy #array #hash_table #string #counting
🟡2131.longest-palindrome-by-concatenating-two-letter-words
🏷️ Tags
#greedy #array #hash_table #string #counting
Telegraph
longest-palindrome-by-concatenating-two-letter-words
You are given an array of strings words. Each element of words consists of two lowercase English letters. Create the longest possible palindrome by selecting some elements from words and concatenating them in any order. Each element can be selected at most…
leetcode.cn 2025-05-26
🔴1857.largest-color-value-in-a-directed-graph
🏷️ Tags
#graph #topological_sort #memoization #hash_table #dynamic_programming #counting
🔴1857.largest-color-value-in-a-directed-graph
🏷️ Tags
#graph #topological_sort #memoization #hash_table #dynamic_programming #counting
Telegraph
largest-color-value-in-a-directed-graph
给你一个 有向图 ,它含有 n 个节点和 m 条边。节点编号从 0 到 n - 1 。 给你一个字符串 colors ,其中 colors[i] 是小写英文字母,表示图中第 i 个节点的 颜色 (下标从 0 开始)。同时给你一个二维数组 edges ,其中 edges[j] = [aj, bj] 表示从节点 aj 到节点 bj 有一条 有向边 。 图中一条有效 路径 是一个点序列 x1 -> x2 -> x3 -> ... -> xk ,对于所有 1 <= i < k ,从 xi 到 xi+1 在图中有一条有向边。路径的…
leetcode.com 2025-05-26
🔴1857.largest-color-value-in-a-directed-graph
🏷️ Tags
#graph #topological_sort #memoization #hash_table #dynamic_programming #counting
🔴1857.largest-color-value-in-a-directed-graph
🏷️ Tags
#graph #topological_sort #memoization #hash_table #dynamic_programming #counting
Telegraph
largest-color-value-in-a-directed-graph
There is a directed graph of n colored nodes and m edges. The nodes are numbered from 0 to n - 1. You are given a string colors where colors[i] is a lowercase English letter representing the color of the ith node in this graph (0-indexed). You are also given…
leetcode.cn 2025-05-28
🟡3372.maximize-the-number-of-target-nodes-after-connecting-trees-i
🏷️ Tags
#tree #depth_first_search #breadth_first_search
🟡3372.maximize-the-number-of-target-nodes-after-connecting-trees-i
🏷️ Tags
#tree #depth_first_search #breadth_first_search
Telegraph
maximize-the-number-of-target-nodes-after-connecting-trees-i
有两棵 无向 树,分别有 n 和 m 个树节点。两棵树中的节点编号分别为[0, n - 1] 和 [0, m - 1] 中的整数。 给你两个二维整数 edges1 和 edges2 ,长度分别为 n - 1 和 m - 1 ,其中 edges1[i] = [ai, bi] 表示第一棵树中节点 ai 和 bi 之间有一条边,edges2[i] = [ui, vi] 表示第二棵树中节点 ui 和 vi 之间有一条边。同时给你一个整数 k 。 如果节点 u 和节点 v 之间路径的边数小于等于 k ,那么我们称节点…
leetcode.com 2025-05-28
🟡3372.maximize-the-number-of-target-nodes-after-connecting-trees-i
🏷️ Tags
#tree #depth_first_search #breadth_first_search
🟡3372.maximize-the-number-of-target-nodes-after-connecting-trees-i
🏷️ Tags
#tree #depth_first_search #breadth_first_search
Telegraph
maximize-the-number-of-target-nodes-after-connecting-trees-i
There exist two undirected trees with n and m nodes, with distinct labels in ranges [0, n - 1] and [0, m - 1], respectively. You are given two 2D integer arrays edges1 and edges2 of lengths n - 1 and m - 1, respectively, where edges1[i] = [ai, bi] indicates…
leetcode.cn 2025-05-29
🔴3373.maximize-the-number-of-target-nodes-after-connecting-trees-ii
🏷️ Tags
#tree #depth_first_search #breadth_first_search
🔴3373.maximize-the-number-of-target-nodes-after-connecting-trees-ii
🏷️ Tags
#tree #depth_first_search #breadth_first_search
Telegraph
maximize-the-number-of-target-nodes-after-connecting-trees-ii
有两棵 无向 树,分别有 n 和 m 个树节点。两棵树中的节点编号分别为[0, n - 1] 和 [0, m - 1] 中的整数。 给你两个二维整数 edges1 和 edges2 ,长度分别为 n - 1 和 m - 1 ,其中 edges1[i] = [ai, bi] 表示第一棵树中节点 ai 和 bi 之间有一条边,edges2[i] = [ui, vi] 表示第二棵树中节点 ui 和 vi 之间有一条边。 如果节点 u 和节点 v 之间路径的边数是偶数,那么我们称节点 u 是节点 v 的 目标节…
leetcode.com 2025-05-29
🔴3373.maximize-the-number-of-target-nodes-after-connecting-trees-ii
🏷️ Tags
#tree #depth_first_search #breadth_first_search
🔴3373.maximize-the-number-of-target-nodes-after-connecting-trees-ii
🏷️ Tags
#tree #depth_first_search #breadth_first_search
Telegraph
maximize-the-number-of-target-nodes-after-connecting-trees-ii
There exist two undirected trees with n and m nodes, labeled from [0, n - 1] and [0, m - 1], respectively. You are given two 2D integer arrays edges1 and edges2 of lengths n - 1 and m - 1, respectively, where edges1[i] = [ai, bi] indicates that there is an…
leetcode.cn 2025-06-01
🟡2929.distribute-candies-among-children-ii
🏷️ Tags
#math #combinatorics #enumeration
🟡2929.distribute-candies-among-children-ii
🏷️ Tags
#math #combinatorics #enumeration
Telegraph
distribute-candies-among-children-ii
给你两个正整数 n 和 limit 。 请你将 n 颗糖果分给 3 位小朋友,确保没有任何小朋友得到超过 limit 颗糖果,请你返回满足此条件下的 总方案数 。 示例 1: 输入:n = 5, limit = 2 输出:3 解释:总共有 3 种方法分配 5 颗糖果,且每位小朋友的糖果数不超过 2 :(1, 2, 2) ,(2, 1, 2) 和 (2, 2, 1) 。 示例 2: 输入:n = 3, limit = 3 输出:10 解释:总共有 10 种方法分配 3 颗糖果,且每位小朋友的糖果数不超过…
leetcode.com 2025-06-01
🟡2929.distribute-candies-among-children-ii
🏷️ Tags
#math #combinatorics #enumeration
🟡2929.distribute-candies-among-children-ii
🏷️ Tags
#math #combinatorics #enumeration
Telegraph
distribute-candies-among-children-ii
You are given two positive integers n and limit. Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies. Example 1: Input: n = 5, limit = 2 Output: 3 Explanation: There are 3 ways to distribute…