Develop

[프로그래머스] 두 수의 연산값 비교하기 본문

개인 공부/프로그래머스

[프로그래머스] 두 수의 연산값 비교하기

개발 기록 2024. 1. 13. 12:57

문제

 

내풀이

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

 

 

다른 풀이

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

 

 

느낀점

 

이번에는 삼항을 사용했으니

다음에는 Math.max함수를 사용해봐야겠다