簡単 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 つずつ開いてみましょう。

ヒント 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 位になりましょう。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。