▼ 내 풀이
class Solution {
public int solution(int a, int b) {
String aa = Integer.toString(a);
String bb = Integer.toString(b);
int ab = Integer.parseInt(aa+bb);
int ba = Integer.parseInt(bb+aa);
int answer = ab >= ba ? ab : ba;
return answer;
}
}
Integer.toString(n) → String
Integer.parseInt(str) → int
▼ 타인의 풀이 1
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;
}
}
String+int → String
Integer.parseInt(str) → int
▼ 타인의 풀이 2
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));
}
}
String.valueOf(n) → String
Integer.valueOf(str) → int
'Study with me > 프로그래머스 L0 마스터하기' 카테고리의 다른 글
프로그래머스 - L0 n번째원소부터 (0) | 2023.12.05 |
---|---|
프로그래머스 - L0 길이에따른연산 (0) | 2023.12.03 |
프로그래머스 - L0 수조작하기1 // String → char sequence (0) | 2023.12.02 |
프로그래머스 - L0 정수찾기 (0) | 2023.12.02 |
프로그래머스 - L0 조건에맞게수열변환하기3 (0) | 2023.12.01 |