Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 63ba174

Browse files
committedAug 7, 2023
solves #2639: FindTheWidthOfColumnsOfAGri in java
1 parent b870a9c commit 63ba174

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed
 

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@
813813
| 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | [![Java](assets/java.png)](src/FormSmallestNumberFromTwoDigitArrays.java) | |
814814
| 2609 | [Find the Longest Balanced Substring of a Binary String](https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string) | [![Java](assets/java.png)](src/FindTheLongestBalancedSubstringOfABinaryString.java) | |
815815
| 2614 | [Prime In Diagonal](https://leetcode.com/problems/prime-in-diagonal) | [![Java](assets/java.png)](src/PrimeInDiagonal.java) | |
816-
| 2639 | [Find the Width of Columns of a Grid](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid) | | |
816+
| 2639 | [Find the Width of Columns of a Grid](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid) | [![Java](assets/java.png)](src/FindTheWidthOfColumnsOfAGrid.java) | |
817817
| 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones) | | |
818818
| 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score) | | |
819819
| 2651 | [Calculate Delayed Arrival Time](https://leetcode.com/problems/calculate-delayed-arrival-time) | | |

‎src/FindTheWidthOfColumnsOfAGrid.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// https://leetcode.com/problems/find-the-width-of-columns-of-a-grid
2+
// m: rows in matrix
3+
// n: columns in matrix
4+
// T: O(m * n)
5+
// S: O(n)
6+
7+
public class FindTheWidthOfColumnsOfAGrid {
8+
public int[] findColumnWidth(int[][] grid) {
9+
final int columns = grid[0].length;
10+
final int[] result = new int[columns];
11+
for (int column = 0 ; column < columns ; column++) {
12+
int maxLen = 0;
13+
for (int[] row : grid) {
14+
maxLen = Math.max(maxLen, (String.valueOf(row[column])).length());
15+
}
16+
result[column] = maxLen;
17+
}
18+
return result;
19+
}
20+
}

0 commit comments

Comments
 (0)
Please sign in to comment.