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

프로그래머스 (181939)
Stupefyee's avatar
Feb 24, 2025
[JAVA 문제 풀이] 103. 더 크게 합치기
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

stupefyee