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
- 문제해결
- greedy
- 코테
- 문자열
- BOJ
- BFS
- oracle
- 코딩테스트
- math
- db
- DP
- 백준
- 건강
- 투포인터
- 이분탐색
- binary search
- COS PRO
- 운동기록
- MySQL
- SQL
- Java
- 러닝일지
- 알고리즘
- 시뮬레이션
- dfs
- SWEA
- 자바
- priorityqueue
- 문제풀이
- 프로그래머스
Archives
- Today
- Total
슈콩
COS PRO 1급 JAVA 소용돌이의 수 본문




[소스 코드]
class Main {
public int solution(int n) {
int[][] map = new int[n][n];
int num = 1;
int top = 0; int bottom = n-1;
int max = n-1; int min = 0;
int answer = 0;
while(num<=n*n){
for(int i=min;i<=max;i++) map[top][i] = num++;
top++;
for(int i=top;i<=bottom;i++) map[i][max] = num++;
max--;
for(int i=max;i>=min;i--) map[i][bottom] = num++;
bottom--;
for(int i=bottom;i>=top;i--) map[min][i] = num++;
min++;
}
for(int i=0;i<n;i++) answer += map[i][i];
return answer;
}
}