inblog logo
|
stupefyee
    알고리즘문제풀기

    [JAVA 문제 풀이] 103. 더 크게 합치기

    프로그래머스 (181939)
    Stupefyee's avatar
    Stupefyee
    Feb 24, 2025
    [JAVA 문제 풀이] 103. 더 크게 합치기
    Contents
    내가 작성한 코드다른 사람의 코드
    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/181939
    notion image
     

    내가 작성한 코드

    class Solution { public int solution(int a, int b) { int result1Int = Integer.parseInt("" + a + b); // 문자열로 변환 후 합치기, 다시 int로 변환 int result2Int = Integer.parseInt("" + b + a); return result1Int >= result2Int ? result1Int : result2Int; // 둘 중에 큰값 반환 } }
     

    다른 사람의 코드

    class Solution { public int solution(int a, int b) { return Math.max(Integer.parseInt(a + "" + b), Integer.parseInt(b + "" + a)); } }
    Math.max()를 활용하여 더 간단하게
     
    Share article
    Contents
    내가 작성한 코드다른 사람의 코드

    stupefyee

    RSS·Powered by Inblog