[프로그래머스] 더 크게 합치기

Seah Lee·2023년 6월 18일
0

프로그래머스

목록 보기
7/57

class Solution {
    public int solution(int a, int b) {
        
        String ex1 = ""+a+b;
        String ex2 = ""+b+a;
        
        int a1 = Integer.parseInt(ex1);
        int a2 = Integer.parseInt(ex2);
        
        if (a1>=a2) return a1;
        else return a2;

    }
}

Integer.valueOf()로 변경해서 풀이 가능

[다른 사람 풀이]

class Solution {
    public int solution(int a, int b) {
        String strA = String.valueOf(a);
        String strB = String.valueOf(b);
        String strSum1 = strA + strB;
        String strSum2 = strB + strA;
        return Math.max(Integer.valueOf(strSum1), Integer.valueOf(strSum2));
    }
}
class Solution {
    public int solution(int a, int b) {
        int answer = 0;
        int aLong = Integer.parseInt(""+a+b);
        int bLong = Integer.parseInt(""+b+a);
        answer = aLong > bLong ? aLong : bLong;

        return answer;
    }
}
profile
성장하는 개발자

0개의 댓글