반응형
    
    
    
  
                              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
                            
                        
                          
                          - HTTP
- 프로그래머스 레벨 2
- 가천대
- Algorithm
- BFS
- 크롤링
- Node.js
- 자바스크립트
- TCP
- javascript
- 프로그래머스
- 타입스크립트
- type challenge
- ip
- 레벨 1
- typescript
- 타입 챌린지
- 수학
- dp
- 쉬운 문제
- 그래프
- socket
- 백준
- 소켓
- dfs
- 문자열
- Crawling
- HTTP 완벽 가이드
- Nestjs
- 알고리즘
                            Archives
                            
                        
                          
                          - Today
- Total
kakasoo
[node.js] 행렬 테두리 회전하기 ( 프로그래머스 레벨2 ) 본문
반응형
    
    
    
  // 프로그래머스 레벨2 행렬 테두리 회전하기를 풀었습니다.
const rotateMap = (map, query) => {
    const [row1, col1, row2, col2] = query.map((el) => el - 1);
    const answer = [];
    for (let i = col1; i < col2; i++) answer.push(map[row1][i]);
    for (let i = row1; i < row2; i++) answer.push(map[i][col2]);
    for (let i = col2; i > col1; i--) answer.push(map[row2][i]);
    for (let i = row2; i > row1; i--) answer.push(map[i][col1]);
    answer.unshift(answer.pop());
    const minValue = Math.min(...answer);
    for (let i = col1; i < col2; i++) map[row1][i] = answer.shift();
    for (let i = row1; i < row2; i++) map[i][col2] = answer.shift();
    for (let i = col2; i > col1; i--) map[row2][i] = answer.shift();
    for (let i = row2; i > row1; i--) map[i][col1] = answer.shift();
    return minValue;
};
const makeMap = (rows, columns) => {
    const map = new Array(rows.length).fill(0);
    for (let i = 0; i < rows; i++) {
        map[i] = new Array(columns)
            .fill(0)
            .map((el, index) => i * columns + index + 1);
    }
    return map;
};
const solution = (rows, columns, queries) => {
    const map = makeMap(rows, columns);
    const answer = [];
    queries.forEach((query) => {
        answer.push(rotateMap(map, query));
    });
    return answer.filter((el) => el !== null);
};
테두리의 꼭지점이 겹치지 않게 for문을 짜다가 오류가 계속 나서,
그냥 스트레스 받아서 겹치게 했다.
겹치게 테두리를 뽑아도, 겹치게 테두리를 내려놓으면 문제가 없으니깐.
반응형
    
    
    
  '프로그래밍 > 알고리즘 풀이' 카테고리의 다른 글
| [node.js] 2개 이하로 다른 비트 ( 프로그래머스 레벨2 ) (0) | 2021.07.01 | 
|---|---|
| [node.js] 이진 변환 반복하기 ( 프로그래머스 레벨2 ) (0) | 2021.07.01 | 
| [node.js] 메뉴 리뉴얼 ( 프로그래머스 레벨2 ) (0) | 2021.06.30 | 
| [node.js] 뉴스 클러스터링 ( 프로그래머스 레벨2 ) (0) | 2021.06.30 | 
| [node.js] 배달 ( 프로그래머스 레벨2 ) (0) | 2021.06.30 | 
 
                   
                   
                  