Develop
[프로그래머스] 두 수의 연산값 비교하기 본문
문제
내풀이
class Solution {
public int solution(int a, int b) {
int ab = Integer.parseInt(a+""+b);
int ab2 = 2*a*b;
return (ab >= ab2)? ab : ab2;
}
}
다른 풀이
class Solution {
public int solution(int a, int b) {
return Math.max(Integer.parseInt(String.valueOf(a)+String.valueOf(b)),2*a*b);
}
}
느낀점
이번에는 삼항을 사용했으니
다음에는 Math.max함수를 사용해봐야겠다
'개인 공부 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 홀짝에 따라 다른 값 반환하기 (0) | 2024.01.15 |
---|---|
[프로그래머스] 진료 순서 정하기 (1) | 2024.01.13 |
[프로그래머스] 더 크게 합치기 (0) | 2024.01.12 |
[프로그래머스] 문자열 곱하기 (0) | 2024.01.12 |
[프로그래머스] 문자열 섞기 (1) | 2024.01.11 |