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
- 구현
- 자바
- Counting
- Method
- bit manipulation
- Binary Tree
- implement
- SQL
- database
- array
- dynamic programming
- Binary Search
- Data Structure
- two pointers
- geometry
- greedy
- simulation
- 코딩테스트
- Stack
- hash table
- sorting
- string
- java
- 코테
- Tree
- Math
- Class
- Number Theory
- 파이썬
- Matrix
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2319. Check if Matrix Is X-Matrix 본문
1. Input
1) int[][] grid
2. Output
1) grid가 x-matrix라면 true, 아니면 false를 반환
- x-matrix는 대각선 요소는 0이 아니고 나머지는 0인 행렬을 말한다.
3. Constraint
1) grid는 n*n 행렬이다.
2) 3 <= n <= 100
3) 0 <= grid[i][j] <= 10^5
4. Example
Input: grid = [[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]] -> Output: true
5. Code
1) 첫 코드(2022/06/27)
for(int i=0 ; i<grid.length ; i++){
for(int j=0 ; j<grid[i].length ; j++){
if(i==j || i+j==grid.length-1){ // diagonals
if(grid[i][j]==0)
return false;
}else{
if(grid[i][j]!=0)
return false;
}
} // for j
} // for i
return true;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2347. Best Poker Hand (0) | 2023.01.16 |
---|---|
[LeetCode/Easy] 2341. Maximum Number of Pairs in Array (0) | 2023.01.16 |
[LeetCode/Easy] 2315. Count Asterisks (0) | 2023.01.16 |
[LeetCode/Easy] 2299. Strong Password Checker II (0) | 2023.01.16 |
[LeetCode/Easy] 2283. Check if Number Has Equal Digit Count and Digit Value (0) | 2023.01.16 |