Skip to content

Commit 48af654

Browse files
authored
Create 프로그래머스_삼각달팽이.java
1 parent e073792 commit 48af654

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution {
2+
public int[] solution(int n) {
3+
int[] answer = new int [n*(n+1)/2];
4+
int [][] array = new int[n][n];
5+
int num = 1;
6+
int x = -1;
7+
int y = 0;
8+
for (int i = 0;i < n;i++) {
9+
for (int j = i; j < n; j++) {
10+
if (i % 3 == 0) {
11+
x++;
12+
} else if(i % 3 == 1) {
13+
y++;
14+
} else {
15+
x--;
16+
y--;
17+
}
18+
array[x][y] = num++;
19+
}
20+
}
21+
int idx = 0;
22+
for (int i = 0; i < n; i++) {
23+
for (int j = 0; j <= i ; j++) {
24+
answer[idx++] = array[i][j];
25+
}
26+
}
27+
return answer;
28+
29+
}}

0 commit comments

Comments
 (0)