문제
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
숫자들을 두 개씩 비교해 가장 큰 값을 찾으세요.
힌트 2
몇 개의 조건문만 있으면 되고, 탐색 구조는 필요 없습니다.
힌트 3
같은 값이 나와도 올바른 최대값을 반환하도록 주의하세요.
예상 복잡도
시간 O(1), 추가 공간 O(1)
참고 자료
이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.