Algorithm/Programmers
[C#]프로그래머스 87390 n^2 배열 자르기 - Hide
zz0zz9
2024. 12. 11. 23:56
반응형
반응형
https://school.programmers.co.kr/learn/courses/30/lessons/87390
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
문제 요약
주어진 과정대로 만들어진 1차원 배열을 반환하는 함수 만들기
풀이
using System;
using System.Linq;
using System.Collections.Generic;
public class Solution {
public int[] solution(int n, long left, long right) {
List<int> list = new List<int>();
for (long i = left / n; i <= right / n; i++)
{
for (int j = 1; j <= n; j++)
{
if (j <= i + 1)
{
list.Add((int)i + 1);
}
else list.Add((int)j);
}
}
int[] answer = list.Skip((int)(left % (long)n)).Take((int)(right - left + 1)).ToArray();
return answer;
}
}
애니메이션으로 설명해 주는 문제라니❤
반응형