💡/코딩 테스트

[프로그래머스] 조건 문자열

defyuil 2024. 5. 9. 22:41

 

 

class Solution {
        public int solution(String ineq, String eq, int n, int m) {
                if (ineq.equals(">")) {
                        if (eq.equals("=")) {
                                return n >= m ? 1 : 0;
                        } else if (eq.equals("!")) {
                                return n > m ? 1 : 0;
                        }
                } else if (ineq.equals("<")) {
                        if (eq.equals("=")) {
                                return n <= m ? 1 : 0;
                        } else if (eq.equals("!")) {
                                return n < m ? 1 : 0;
                        }
                }

                return 0;
        }
}

 

더보기

ineq 가 > 일 때, < 일 때를 나누고 그 안에서 eq 가 = 일 때와 ! 일 때를 구분했다

그리고 return 하는 것을 삼항 연산자를 이용하여 풀었다