We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 57c20f7 + f4b20a8 commit 8d5bcdaCopy full SHA for 8d5bcda
1 file changed
2025-09-12/김소희/프로그래머스_삼각달팽이.java
@@ -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
24
+ for(int j=0; j<=i; j++){
25
+ answer[index++]=arr[i][j];
26
27
28
+ return answer;
29
30
+}
0 commit comments