Advertisement
2639. Find the Width of Columns of a Grid
UnknownView on LeetCode
Time: O(mn * digits)
Space: O(n)
Approach
For each column track max string width of each integer (handle negative sign).
2639.cs
C#
// Approach: For each column track max string width of each integer (handle negative sign).
// Time: O(mn * digits) Space: O(n)
public class Solution
{
public int[] FindColumnWidth(int[][] grid)
{
int m = grid.Length;
int n = grid[0].Length;
int[] ans = new int[n];
for (int j = 0; j < n; j++)
{
for (int i = 0; i < m; i++)
{
ans[j] = Math.Max(ans[j], grid[i][j].ToString().Length);
}
}
return ans;
}
}Advertisement
Was this solution helpful?