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 | 31 |
Tags
- java
- 자바
- simulation
- two pointers
- 코테
- Stack
- Method
- Data Structure
- greedy
- sorting
- implement
- Matrix
- Binary Tree
- Tree
- dynamic programming
- Class
- 구현
- geometry
- array
- Math
- database
- hash table
- 파이썬
- string
- Counting
- Binary Search
- Number Theory
- bit manipulation
- 코딩테스트
- SQL
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1252. Cells with Odd Values in a Matrix 본문
1. Input
1) 정수 m
2) 정수 n
3) 1 증가시킬 행과 열을 담은 2차원 배열 indices
2. Output
1) m행 n열 매트릭스의 요소가 모두 0일 때, indices에 따라 행과 열을 1씩 증가시킨 후, 그 중 홀수가 몇개인지 반환
2) indices의 요소는 [r, c]이고, r은 증가시킬 행의 번호, c는 증가시킬 열의 변호이다.
3. Constraint
1) 1 <= m, n <= 50
2) 1 <= indices.length <= 100
3) 0 <= r < m
4) 0 <= c < n
4. Example
Input: m = 2, n = 3, indices = [[0,1],[1,1]] -> Output: 6
설명:
- 홀수는 총 6개이므로 6을 반환한다.
5. Code
1) 첫 코드(2022/06/10)
int[][] matrix = new int[m][n];
// indice에 따라 1씩 더하기
int r=0, c=0;
for(int i=0 ; i<indices.length ; i++){
r = indices[i][0];
c = indices[i][1];
for(int j=0 ; j<n ; j++)
matrix[r][j]++;
for(int j=0 ; j<m ; j++)
matrix[j][c]++;
}
// 홀수 찾기
int count = 0;
for(int i=0 ; i<m ; i++)
for(int j=0 ; j<n ; j++)
if(matrix[i][j]%2 != 0)
count++;
return count;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1281. Subtract the Product and Sum of Digits of an Integer (0) | 2022.12.24 |
---|---|
[LeetCode/Easy] 1266. Minimum Time Visiting All Points (0) | 2022.12.24 |
[LeetCode/Easy] 1221. Split a String in Balanced Strings (0) | 2022.12.23 |
[LeetCode/Easy] 1154. Day of the Year (0) | 2022.12.20 |
[LeetCode/Easy] 1137. N-th Tribonacci Number (0) | 2022.12.20 |