모든 챌린지
쉬움 6명 해결 정답률 85.7%

Largest of Three

Pick the largest of three numbers without a built-in max.

배우게 될 내용

  • Compare values without a built-in max
  • Combine conditions with and
  • Handle equal values

문제

번역본 보기

Return the largest of three integers. Practice comparisons with if statements; don't use a built-in max function.

Implement largest_of_three(a, b, c).

Input

a: The first number. b: The second number. c: The third number.

Output

Return the largest value.

제약 조건

-1,000,000,000 ≤ a, b, c ≤ 1,000,000,000

예시

예시 1
입력:
a = 3
b = 9
c = 4

예상 출력:
expected = 9
입력:
long long a = 3;
long long b = 9;
long long c = 4;

예상 출력:
long long expected = 9;
입력:
long a = 3;
long b = 9;
long c = 4;

예상 출력:
long expected = 9;

설명

9 is greater than both 3 and 4.

예시 2
입력:
a = -5
b = -2
c = -2

예상 출력:
expected = -2
입력:
long long a = -5;
long long b = -2;
long long c = -2;

예상 출력:
long long expected = -2;
입력:
long a = -5;
long b = -2;
long c = -2;

예상 출력:
long expected = -2;

설명

-2 appears twice and is the largest value.

접근 방법

먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.

힌트 1

Compare the numbers pair by pair to identify the largest one.

힌트 2

A few conditional checks are enough; no search structure is needed.

힌트 3

Be careful with equal values, since ties should still return the correct largest number.

예상 복잡도

O(1) time, O(1) extra space

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제약 조건을 기준으로 풀어 주세요.

코더마다 가장 좋은 통과 풀이입니다. 더 빠르고, 메모리를 덜 쓰고, 평가가 좋은 풀이가 위에 옵니다.

# 코더 언어 시간 메모리 AI 평가 풀이
1 ДЗДавид Зайдулин Python 799 ms - 3/5 코드 보기
2 RCRiccardo Corti Python 847 ms - 5/5 코드 보기
3 KKKaneki Ken Python 850 ms - 4/5 코드 보기
4 LMLaura Mahlow Python 850 ms - 3/5 코드 보기
5 HJhettory Jurash C++ 3,162 ms - 2/5 코드 보기
6 PTphúc thịnh phạm C++ 3,269 ms - 4/5 코드 보기

다른 사람의 풀이 보기

커뮤니티 풀이

스포일러: 아래에 전체 풀이 6개가 있습니다 먼저 직접 풀어보세요. 다른 개발자의 코드와 AI 리뷰도 참고할 수 있습니다. 로그인하고 문제를 풀면 토론에 참여할 수 있습니다.