코딩공부/프로그래머스

[프로그래머스]Lv.0 수열과 구간 쿼리 2 C#

usingsystem 2023. 6. 2. 16:53
728x90

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

소스코드

  public int[] solution(int[] arr, int[,] queries)
    {
        int[] answer = new int[queries.GetLength(0)];

        for (int i = 0; i < queries.GetLength(0); i++)
        {
            int s = queries[i, 0];
            int e = queries[i, 1];
            int k = queries[i, 2];

            int result = -1;
            for (int j = s; j <= e; j++)
            {
                if (arr[j] > k && result == -1)
                    result = arr[j];
                if (result > arr[j])
                    result = arr[j];
            }
            answer[i] = result;
        }
        return answer;
    }
728x90