Skip to content

[PGS] 삼각달팽이 - #97

Open
gayo73 wants to merge 1 commit into
mainfrom
gayo-#17
Open

[PGS] 삼각달팽이#97
gayo73 wants to merge 1 commit into
mainfrom
gayo-#17

Conversation

@gayo73

@gayo73 gayo73 commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

🍪 문제 이름

Resolve: https://school.programmers.co.kr/learn/courses/30/lessons/68645


🍊 문제 정의

input

  • 정수 n

output

  • 밑변의 길이와 높이가 n인 삼각형에서 맨 위 꼭짓점부터 반시계 방향으로 달팽이 채우기를 진행한 후, 첫 행부터 마지막 행까지 모두 순서대로 합친 새로운 배열을 return

🍑 알고리즘 설계

int x = -1, y = 0;
        int num = 1;
        for(int i=0; i<n; i++){
            if(i%3==0){
                for(int j=0; j<n-i; j++){
                    arr[++x][y] = num++;
                }
            }
            else if(i%3==1){
                for(int j=0; j<n-i; j++){
                    arr[x][++y] = num++;
                }
            }
            else{
                for(int j=0; j<n-i; j++){
                    arr[--x][--y] = num++;
                }
            }
        }
        
        answer = new int[num-1];
        int idx = 0;
        for(int i=0; i<arr.length; i++){
            for(int j=0; j<=i; j++){
                answer[idx++] = arr[i][j];
            }
        }

🥝 최악 수행 시간 복잡도

  • O()

🍰 특이 사항 (Optional)

참고 자료나 추가로 설명하고 싶은 내용을 작성해 주세요.

@gayo73
gayo73 requested review from been12151 and yangyeeeun July 22, 2026 13:20
@gayo73 gayo73 self-assigned this Jul 22, 2026
@gayo73 gayo73 added the 구현 label Jul 22, 2026
@gayo73 gayo73 linked an issue Jul 22, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PGS] 삼각 달팽이 / level 2

1 participant