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

Smallest of Three

Return the smallest of three integers.

배우게 될 내용

  • Keep track of the best value so far
  • Compare values with if statements
  • Handle ties and negative numbers

문제

번역본 보기

Three friends compare how many minutes they were late this week and the one who was late the least gets to pick lunch. Given the three numbers, find the smallest. Some values can be equal, and they can be negative (early).

Implement smallest_of_three(a, b, c).

Input

a: The first number.

b: The second number.

c: The third number.

Output

Return the smallest of the three values. If several are equal and smallest, return that value.

제약 조건

−10^18 ≤ a, b, c ≤ 10^18

예시

예시 1
입력:
a = 7
b = 15
c = 3

예상 출력:
expected = 3
입력:
long long a = 7;
long long b = 15;
long long c = 3;

예상 출력:
long long expected = 3;
입력:
long a = 7;
long b = 15;
long c = 3;

예상 출력:
long expected = 3;

설명

3 is less than both 7 and 15.

예시 2
입력:
a = -4
b = -4
c = 10

예상 출력:
expected = -4
입력:
long long a = -4;
long long b = -4;
long long c = 10;

예상 출력:
long long expected = -4;
입력:
long a = -4;
long b = -4;
long c = 10;

예상 출력:
long expected = -4;

설명

The two −4 values tie for smallest, so the answer is −4.

접근 방법

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

힌트 1

Assume the first number is the smallest.

힌트 2

Compare it with the second and then the third, updating when you find a smaller one.

힌트 3

Use a 64-bit integer type, the values can be very large.

예상 복잡도

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

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

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

아직 통과한 풀이가 없습니다. 풀어서 1위를 차지하세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.