1857. Largest Color Value in a Directed Graph
Problem
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 edges
where
A valid path in the graph is a sequence of nodes
Return the largest color value of any valid path in the given graph, or -1
if the graph contains a cycle.
Example 1:
Input: colors = "abaca", edges = [[0,1],[0,2],[2,3],[3,4]]
Output: 3
Explanation: The path 0 -> 2 -> 3 -> 4 contains 3 nodes that are colored "a" (red in the above image).
Example 2:
Input: colors = "a", edges = [[0,0]]
Output: -1
Explanation: There is a cycle from 0 to 0.
Constraints:
n == colors.length
m == edges.length
colors
consists of lowercase English letters.
Code
按 <- 键看上一题!
1853. Convert Date Format
按 -> 键看下一题!
1867. Orders With Maximum Quantity Above Average