NeetCode #646LC-2421HardAdvanced Graphs
← Back to All Problems

#646 · #2421 · Number of Good Paths(好路径的数目)

📌 Problem Statement & Constraints

You are given a tree of n nodes with vals[i] and edges. A good path is a simple path whose two endpoints have the same value and every node on it has a value at most that value. Return the number of good paths. Constraints: 1 <= n <= 3 * 10^4, 1 <= vals[i] <= 10^5.
🔒

Sign In to Unlock Full Solutions for All 973 Problems

Sign in to access step-by-step logic, benchmark Python3 code, complexity breakdown, and offline export!