코딩테스트_c#/프로그래머스
프로그래머스 ) 코딩 기초 트레이닝 - 배열 조각하기_C#
노년인생
2024. 2. 13. 20:10
728x90
반응형
배열 조각하기 문제
내 코드
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(int[] arr, int[] query) {
List<int> answer = new List<int>(arr);
for (int i = 0; i < query.Length; i++)
{
//012345 //412 >> 4 //01234 // >>1 //1234 // >>2 //123
if (i % 2 == 0)
{
for (int j = answer.Count-1; j > query[i]; j--)
{
answer.RemoveAt(j);
}
}
else
{
for (int j = 0; j < query[i]; j++)
{
answer.RemoveAt(0);
}
}
arr = answer.ToArray();
}
return answer.ToArray();
}
}
728x90
반응형