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;
}
}
문자열에 int를 이어붙이면,
문자열이 리턴되는 속성을 이용한 방법입니다
출처: https://hianna.tistory.com/524 [어제 오늘 내일:티스토리]
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));
}
}
math.max 메소드 사용한 거
class Solution {
public int solution(int a, int b) {
return Math.max(Integer.parseInt(a + "" + b), Integer.parseInt(b + "" + a));
}
}
'알고리즘 공부' 카테고리의 다른 글
자바 boolean (2) | 2023.12.03 |
---|---|
if문 (2) | 2023.12.03 |
[Java] String.join 메소드 (0) | 2023.11.27 |
삼항연산 (0) | 2023.11.17 |
Java 문자열 대문자 소문자 바꾸기 (0) | 2023.11.13 |