Легко Решено: 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. Следуйте условию и ограничениям выше.

Лучшее принятое решение каждого участника. Более быстрые, экономные и высоко оценённые решения стоят выше.

Принятых решений пока нет. Решите задачу и займите первое место.

Учитесь у других

Решения сообщества

Пока нет опубликованных решений. Решите задание, чтобы поделиться первым.