코린이의 소소한 공부노트

[프로그래머스/Lv.0] 첫 번째로 나오는 음수 본문

코딩테스트 풀이/JAVA

[프로그래머스/Lv.0] 첫 번째로 나오는 음수

무지맘 2023. 4. 24. 18:25

1. Input, Output, Example

- 첫 번째로 나오는 음수의 인덱스를 반환

- 음수가 없다면 -1을 반환

 

2. Constraint

1) 5 num_list의 길이 100

2) -10 num_list의 원소 100

 

3. Code

1) 첫 코드(2023/04/24)

class Solution {
    public int solution(int[] num_list) {
        int answer = -1;
        for(int i=0 ; i<num_list.length ; i++)
            if(num_list[i]<0){
                answer = i;
                break;
            }
        return answer;
    }
}