We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9f53554 commit ddfe102Copy full SHA for ddfe102
1 file changed
ksinji/202511/8 PGM 삼각 달팽이.md
@@ -0,0 +1,44 @@
1
+```java
2
+import java.util.*;
3
+
4
+class Solution {
5
+ public int[] solution(int n) {
6
+ int total = n * (n + 1) / 2;
7
+ int[][] tri = new int[n][n];
8
9
+ int num = 1;
10
+ int r = -1;
11
+ int c = 0;
12
+ int len = n;
13
14
+ while (len > 0) {
15
+ for (int i = 0; i < len; i++) {
16
+ tri[++r][c] = num++;
17
+ }
18
+ len--;
19
+ if (len == 0) break;
20
21
22
+ tri[r][++c] = num++;
23
24
25
26
27
28
+ tri[--r][--c] = num++;
29
30
31
32
33
+ int[] answer = new int[total];
34
+ int idx = 0;
35
+ for (int i = 0; i < n; i++) {
36
+ for (int j = 0; j <= i; j++) {
37
+ answer[idx++] = tri[i][j];
38
39
40
+ return answer;
41
42
+}
43
44
+```
0 commit comments