Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- bit manipulation
- Binary Tree
- Counting
- java
- Stack
- SQL
- Tree
- 자바
- Binary Search
- sorting
- geometry
- 파이썬
- dynamic programming
- hash table
- greedy
- 코테
- string
- implement
- database
- Math
- 코딩테스트
- array
- Number Theory
- Class
- two pointers
- Data Structure
- Matrix
- Method
- simulation
- 구현
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2639. Find the Width of Columns of a Grid 본문
1. Input
1) int[][] grid
2. Output
1) grid의 각 열별로 가장 긴 숫자의 길이를 담은 배열을 반환
- 음수일 경우 -도 길이에 포함시켜야 한다.
3. Constraint
1) m == grid.length
2) n == grid[i].length
3) 1 <= m, n <= 100
4) - 10^9 <= grid[r][c] <= 10^9
4. Example
Input: grid = [[-15,1,3],[15,7,12],[5,6,-2]] -> Output: [3,1,2]
설명:
- 1번째 열: -15, 15, 5의 길이는 3, 2, 1 -> 3
- 2번째 열: 1, 7, 6의 길이는 모두 1 -> 1
- 3번째 열: 3, 12, -1의 길이는 1, 2, 2 -> 2
5. Code
1) 첫 코드(2023/05/08)
class Solution {
public int[] findColumnWidth(int[][] grid) {
int[] answer = new int[grid[0].length];
for(int j=0 ; j<grid[0].length ; j++){
int max = 0;
for(int i=0 ; i<grid.length ; i++)
max = Math.max(max, String.valueOf(grid[i][j]).length());
answer[j] = max;
}
return answer;
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2644. Find the Maximum Divisibility Score (0) | 2023.05.08 |
---|---|
[LeetCode/Easy] 2643. Row With Maximum Ones (0) | 2023.05.08 |
[LeetCode/Easy] 2614. Prime In Diagonal (0) | 2023.05.08 |
[LeetCode/Easy] 2605. Form Smallest Number From Two Digit Arrays (0) | 2023.05.06 |
[LeetCode/Easy] 2582. Pass the Pillow (0) | 2023.05.06 |