2639. Find the Width of Columns of a Grid Poison 2024-04-27 12345678910111213141516171819202122232425262728293031323334353637class Solution { public int[] findColumnWidth(int[][] grid) { int m = grid.length, n = grid[0].length; int[] ans = new int[n]; for (int j = 0; j < n; j++) { int min = grid[0][j], max = grid[0][j]; for (int i = 1; i < m; i++) { min = Math.min(min, grid[i][j]); max = Math.max(max, grid[i][j]); } ans[j] = Math.max(getWidth(min), getWidth(max)); } return ans; } private int getWidth(int num) { if (num == 0) { return 1; // 注意数字 0 的宽度为 1 而不是 0 } int width = 0; if (num < 0) { width++; num = -num; } while (num > 0) { width++; num /= 10; } return width; }} References2639. Find the Width of Columns of a Grid