본문 바로가기
코딩테스트/프로그래머스 Lv.0

[코테/0레벨] 두 수의 연산값 비교하기

by moca7 2025. 2. 11.

 

 

 

 

ㅁ 내 풀이

 

class Solution {
    public int solution(int a, int b) {
        
        String first1 = String.valueOf(a) + String.valueOf(b);
        int first2 = Integer.parseInt(first1);
        int second = 2 * a * b;
        
        if(first2 == second){
            return first2;
        }else{
            return Math.max(first2, second);
        }
        
    }
}

 

 

 

ㅁ 다른 풀이

 

class Solution {
    public int solution(int a, int b) {
        int ab = Integer.parseInt(Integer.toString(a) + Integer.toString(b));
        int ab2 = 2 * a * b;
        return ab == ab2 ? ab : Math.max(ab, ab2);
    }
}