Skip to content

Commit 8d5bcda

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/main'
2 parents 57c20f7 + f4b20a8 commit 8d5bcda

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)