class Solution {
public int solution(int a, int b) {
int answer = 0;
return answer;
}
}
해결법
방법 1
class Solution {
public int solution(int a, int b) {
int answer = 0;
String strA = a + "";
String strB = b + "";
int sum = Integer.parseInt(strA + strB);
if (sum != 2 * a * b) {
answer = Math.max(sum, 2 * a * b);
} else {
answer = sum;
}
return answer;
}
}
방법 2
class Solution {
public int solution(int a, int b) {
return Math.max(Integer.parseInt(String.valueOf(a)+String.valueOf(b)),2*a*b);
}
}
- Integer.parseInt(String.valueOf(a)+String.valueOf(b))
방법 3
class Solution {
public int solution(int a, int b) {
int ab = Integer.parseInt(a + "" + b);
if (2 * a * b <= ab) {
return ab;
} else {
return 2 * a * b;
}
}
}
두 수의 연산값 비교하기 Lv. 0