포스트

두 수의 연산값 비교하기

https://school.programmers.co.kr/learn/courses/30/lessons/181938

문제

  • 문제 풀이
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
    public int solution(int a, int b) {
        String abConcat = String.valueOf(a) + String.valueOf(b); // 두 수를 붙여서 만든 문자열
        
        int abInt = Integer.parseInt(abConcat); // 두 수를 붙여서 만든 숫자
        int multiplied = 2 * a * b; // 2 * a * b

        if (abInt >= multiplied) {
            return abInt;
        } else {
            return multiplied;
        }
    }
}
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.