#2639
Find the Width of Columns of a Grid
pupil · 300 · lc easy +20 · verified · 70.4% accepted · 194 likes · top 79%
Description
You are given a 0-indexed m x n integer matrix grid. The width of a column is the maximum string length of its values, where negative integers include the minus sign. Return an array ans of size n where ans[i] is the width of column i.
Example 1:
Input: grid = [[1],[22],[333]]
Output: [3]
Explanation: In the 0th column, 333 is of length 3.
Example 2:
Input: grid = [[-15,1,3],[15,7,12],[5,6,-2]]
Output: [3,1,2]
Explanation:
In the 0th column, only -15 is of length 3.
In the 1st column, all integers are of length 1.
In the 2nd column, both 12 and -2 are of length 2.
Code
1
2
3