코딩 테스트 (Java)/코딩 기초 트레이닝 (프로그래머스)

181939. 더 크게 합치기

가지코딩 2025. 4. 1. 14:42

https://school.programmers.co.kr/learn/courses/30/lessons/181939

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr


문제

연산 ⊕는 두 정수에 대한 연산으로 두 정수를 붙여서 쓴 값을 반환합니다. 예를 들면 다음과 같습니다.

  • 12 ⊕ 3 = 123
  • 3 ⊕ 12 = 312

양의 정수 ab가 주어졌을 때, abba 중 더 큰 값을 return 하는 solution 함수를 완성해 주세요.

단, abba가 같다면 ab를 return 합니다.

 

제한사항

  • 1 ≤ a, b < 10,000

 

입출력 예

a b result
9 91 991
89 8 898

 

입출력 예 #1

  • ab = 991 이고, ba = 919 입니다. 둘 중 더 큰 값은 991 이므로 991을 return 합니다.

입출력 예 #2

  • ab = 898 이고, ba = 889 입니다. 둘 중 더 큰 값은 898 이므로 898을 return 합니다.

풀이

class Solution {
    public int solution(int a, int b) {
        int answer = Math.max(Integer.parseInt(a + "" + b), Integer.parseInt(b + "" + a));
        return answer;
    }
}

 

 

 


GitHub: https://github.com/gajicoding/coding_test/edit/main/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4/0/181939.%E2%80%85%EB%8D%94%E2%80%85%ED%81%AC%EA%B2%8C%E2%80%85%ED%95%A9%EC%B9%98%EA%B8%B0

 

coding_test/프로그래머스/0/181939. 더 크게 합치기 at main · gajicoding/coding_test

This is an auto push repository for Baekjoon Online Judge created with [BaekjoonHub](https://github.com/BaekjoonHub/BaekjoonHub). - gajicoding/coding_test

github.com


출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges

 

코딩테스트 연습 | 프로그래머스 스쿨

개발자 취업의 필수 관문 코딩테스트를 철저하게 연습하고 대비할 수 있는 문제를 총망라! 프로그래머스에서 선발한 문제로 유형을 파악하고 실력을 업그레이드해 보세요!

school.programmers.co.kr