배열 만들기 5

개발조개·2026년 9월 8일

문제

코드

public class Solution
{
    public int[] solution(string[] intStrs, int k, int s, int l)
    {
        int[] answer = new int[intStrs.Length];

        for(int i = 0; i < intStrs.Length; i++)
        {
            answer[i] = int.Parse(intStrs[i].Substring(s, l));                    
        }

        var answer2 = answer.Where(se => se > k).ToArray();
        return answer2;
    }
}

참고할 코드

using System;
using System.Linq;

public class Solution {
    public int[] solution(string[] intStrs, int k, int s, int l) 
    {
        return intStrs.Select(e => int.Parse(e.Substring(s, l)))
                      .Where(w => w > k).ToArray();
    }
}

배운점

Linq 기능으로 뭘 더 할 수 있지 않았을까 했는데 역시 다른 사람의 풀이를 보니 Linq로 깔끔하게 작성되어 있었다. select 기능을 좀 더 연습해봐야겠다.

0개의 댓글