728x90
문제 설명
연산 ⊕는 두 정수에 대한 연산으로 두 정수를 붙여서 쓴 값을 반환합니다. 예를 들면 다음과 같습니다.
- 12 ⊕ 3 = 123
- 3 ⊕ 12 = 312
양의 정수 a와 b가 주어졌을 때, a ⊕ b와 b ⊕ a 중 더 큰 값을 return 하는 solution 함수를 완성해 주세요.
단, a ⊕ b와 b ⊕ a가 같다면 a ⊕ b를 return 합니다.
제한사항
- 1 ≤ a, b < 10,000
class Solution {
public int solution(int a, int b) {
int answer = 0;
int ab = Integer.parseInt(String.valueOf(a) + String.valueOf(b));
int ba = Integer.parseInt(String.valueOf(b) + String.valueOf(a));
answer = ab >= ba ? ab : ba;
return answer;
}
}
노트
- Math.max() 메서드면 삼항연산자 안 써도 되자낭..
class Solution {
public int solution(int a, int b) {
int answer = 0;
int ab = Integer.parseInt(String.valueOf(a) + String.valueOf(b));
int ba = Integer.parseInt(String.valueOf(b) + String.valueOf(a));
answer = Math.max(ab, ba);
return answer;
}
}728x90
'○ 기술면접 > 알고리즘' 카테고리의 다른 글
| 연산: 문자열 곱하기 (1) | 2023.06.09 |
|---|---|
| 연산: 문자 리스트를 문자열로 변환하기 (0) | 2023.06.09 |
| 배열: n번째 원소까지 (0) | 2023.06.09 |
| 해시: 완주하지 못한 선수 (0) | 2023.06.08 |
| 해시: 폰켓몬 (0) | 2023.06.08 |
| 프로그래머스: 짝수는 싫어요 (0) | 2023.06.07 |
| 구현: 팰린드롬수 (백준 1259) (0) | 2023.03.27 |
| 이진탐색: Hunt The Rabbit (백준 13777) (0) | 2023.03.24 |