← 返回 google 的题目列表Find the Longest Continuous Line of Same Color in a Bitmap
类型:online_judge
google
Given an N×N pixel grid, each pixel has a color. Find the longest continuous line of the same color. The line can be horizontal, vertical, or diagonal.
Input Description:
An N×N integer matrix grid representing the pixel grid, where 1 <= N <= 100. Values in the matrix are integers, representing colors.
Output Description:
Return an integer indicating the length of the longest continuous line of the same color.
Example:
Input: [[1, 2, 2], [2, 2, 2], [1, 1, 2]]
Output: 3
Constraints: The algorithm should run in O(n^2) time with moderate space complexity.
Example
Input
[[1,2,2],[2,2,2],[1,1,2]]