We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e073792 commit 48af654Copy full SHA for 48af654
1 file changed
2025-08-21/김태민/프로그래머스_삼각달팽이.java
@@ -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