코딩테스트/[C#] 프로그래머스

[프로그래머스 | C# | Lv.0] 가까운 1 찾기

냠냠쿠 2023. 9. 9. 20:30
728x90

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

📝 나의 풀이

using System;

public class Solution {
    public int solution(int[] arr, int idx) {
        int answer = -1;
        
        for(int i=idx; i<arr.Length; i++){
            if(arr[idx]<=arr[i] && arr[i]==1){
                answer=i;
                break;
            }
        }
        return answer;
    }
}

 

 

728x90