//구글콘솔 광고 추가가
배열 조각하기 문제

 

내 코드
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

+ Recent posts