일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 프로그래머스
- zeros
- machine learning
- 방송통신대학교
- 개발자
- 조지아텍
- Deep learning
- C++
- leetcode
- 코딩테스트
- 딥러닝
- 캐나다 영주권
- 매트랩
- 알고리즘
- Plotting
- mpnp
- EOI
- 머신러닝
- 방통대
- 위니펙
- 온라인석사
- 주정부이민
- 컴퓨터과학과
- 기본
- cpp
- 선형대수
- MATLAB
- omscs
- LV1
- LAA
Archives
- Today
- Total
Byte by Byte
766. Toeplitz Matrix.cpp 본문
🔑 재귀함수를 이용한 전체 탐색.
class Solution {
public:
bool res = true;
void check(int x, int y, int xlimit, int ylimit, int start, vector<vector<int>>& matrix){
if(x == xlimit || y == ylimit) return;
if(start != matrix[x][y]){
res = false;
}
x++; y++;
check(x,y,xlimit,ylimit,start,matrix);
return;
}
bool isToeplitzMatrix(vector<vector<int>>& matrix) {
int row = matrix.size();
int col = matrix[0].size();
for(int i = 0; i<row; i++){
check(i,0,row,col,matrix[i][0], matrix);
}
for(int j =0; j<col; j++){
check(0,j,row,col,matrix[0][j], matrix);
}
return res;
}
};
✔ disscussion에 있는 다른 방법
bool isToeplitzMatrix(vector<vector<int>>& matrix) {
int m = matrix.size(), n = matrix[0].size();
for (int i = 1; i < m; i++)
for (int j = 1; j < n; j++)
if (matrix[i][j] != matrix[i - 1][j - 1])
return false;
return true;
}
'개발 로그 > 알고리즘' 카테고리의 다른 글
290. Word Pattern.cpp (0) | 2021.11.25 |
---|---|
202. Happy Number.cpp (0) | 2021.11.24 |
1700. Number of Students Unable to Eat Lunch.cpp (0) | 2021.11.21 |
349. Intersection of Two Arrays.cpp (0) | 2021.11.20 |
1636. Sort Array by Increasing Frequency.cpp (0) | 2021.11.20 |