LeetCode 2639. Find the Width of Columns of a Grid-环球今亮点

2023-04-16 11:55:15来源:哔哩哔哩

You are given a 0-indexed m x ninteger matrix grid. The width of a column is the maximum length of its integers.

For example, if grid = [[-10], [3], [12]], the width of the only column is 3since -10is of length 3.

Return an integer array ansof size nwhere ans[i]is the width of the ithcolumn.


(资料图片仅供参考)

The length of an integer xwith lendigits is equal to lenif xis non-negative, and len + 1otherwise.

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.

Constraints:

m == grid.length

n == grid[i].length

1 <= m, n <= 100

-109 <= grid[r][c] <= 109

其实用字符串自带的length函数最快了,所以我是转成字符串,求出来对应的值,然后返回的

Runtime: 6 ms, faster than 100.00% of Java online submissions for Find the Width of Columns of a Grid.

Memory Usage: 44.1 MB, less than 100.00% of Java online submissions for Find the Width of Columns of a Grid.

标签:

上一篇:全球实时:元宵节手抄报2022简单又漂亮_元宵节手抄报简笔画
下一篇:最后一页