본문 바로가기

알고리즘 테스트 공부

간단한 논리 연산

class Solution {
    public boolean solution(boolean x1, boolean x2, boolean x3, boolean x4) {
        boolean answer = (x1||x2)&&(x3||x4);
        if(answer == true) return answer;
        else return false;
        
       // (x1||x2)&&(x3||x4)
        
    }
}

 

 

 

다른풀이!!1

class Solution {
    public boolean solution(boolean x1, boolean x2, boolean x3, boolean x4) {
        return (x1||x2)&&(x3||x4);
    }

한번에 끝내기,,,!!

 

 

 

import java.util.*;

class Solution {
    public boolean solution(boolean x1, boolean x2, boolean x3, boolean x4) {
        Map<String, Boolean> first = new HashMap<>();

        first.put("00", true);
        first.put("01", true);
        first.put("10", true);
        first.put("11", false);

        Map<String, Boolean> second = new HashMap<>();

        second.put("00", true);
        second.put("01", false);
        second.put("10", false);
        second.put("11", false);

        StringBuilder str = new StringBuilder();

        str.append(x1 ? "0" : "1").append(x2 ? "0" : "1");

        boolean answer = first.get(str.toString());

        str = new StringBuilder();

        str.append(x3 ? "0" : "1").append(x4 ? "0" : "1");

        StringBuilder str2 = new StringBuilder();

        str2.append(answer ? "0" : "1").append(first.get(str.toString()) ? "0" : "1");

        return second.get(str2.toString());
    }
    }

'알고리즘 테스트 공부' 카테고리의 다른 글

주사위게임 3  (1) 2024.01.09
배열만들기 4  (1) 2024.01.08
콜라츠 수열만들기  (0) 2024.01.04
카운트 업  (1) 2024.01.03
배열 만들기 2  (0) 2024.01.02