Einfach 0 gelöst 0% Erfolgsquote

Smallest of Three

Return the smallest of three integers.

Das lernst du

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

Problem

Übersetzung anzeigen

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.

Einschränkungen

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

Beispiele

Beispiel 1
Eingabe:
a = 7
b = 15
c = 3

Erwartete Ausgabe:
expected = 3
Eingabe:
long long a = 7;
long long b = 15;
long long c = 3;

Erwartete Ausgabe:
long long expected = 3;
Eingabe:
long a = 7;
long b = 15;
long c = 3;

Erwartete Ausgabe:
long expected = 3;

Erläuterung

3 is less than both 7 and 15.

Beispiel 2
Eingabe:
a = -4
b = -4
c = 10

Erwartete Ausgabe:
expected = -4
Eingabe:
long long a = -4;
long long b = -4;
long long c = 10;

Erwartete Ausgabe:
long long expected = -4;
Eingabe:
long a = -4;
long b = -4;
long c = 10;

Erwartete Ausgabe:
long expected = -4;

Erläuterung

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

So gehst du vor

Versuch es zuerst allein und öffne dann einen Hinweis nach dem anderen.

Hinweis 1

Assume the first number is the smallest.

Hinweis 2

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

Hinweis 3

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

Erwartete Komplexität

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

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Die beste bestandene Lösung jedes Coders. Schnellere, sparsamere und besser bewertete Lösungen stehen weiter oben.

Noch keine bestandene Lösung. Löse sie und hol dir Platz eins.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.