簡単 7件解決済み 正答率87.5%

Largest of Three

Pick the largest of three numbers without a built-in max.

このチャレンジで学べること

  • Compare values without a built-in max
  • Combine conditions with and
  • Handle equal values

問題

翻訳を表示

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

ヒント 1

Compare the numbers pair by pair to identify the largest one.

ヒント 2

A few conditional checks are enough; no search structure is needed.

ヒント 3

Be careful with equal values, since ties should still return the correct largest number.

目安の計算量

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

参考資料

この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。

ランキング

全体ランキング

コーダーごとのいちばん良い合格解答です。速く、メモリが少なく、評価が高い解答ほど上位になります。

# コーダー 言語 時間 メモリ AI 評価 解答
1 ДЗДавид Зайдулин Python 799 ms - 3/5 コードを見る
2 RCRiccardo Corti Python 847 ms - 5/5 コードを見る
3 KKKaneki Ken Python 850 ms - 4/5 コードを見る
4 LMLaura Mahlow Python 850 ms - 3/5 コードを見る
5 PKPornchai Kaewkrabil Go 1,185 ms - 2/5 コードを見る
6 HJhettory Jurash C++ 3,162 ms - 2/5 コードを見る
7 PTphúc thịnh phạm C++ 3,269 ms - 4/5 コードを見る

他の人の解答から学ぶ

コミュニティの解答

ネタバレ注意: この下に解答が7件あります まずは自分で挑戦してみましょう。他の開発者のコードやAIレビューも見ることができます。 サインインして課題を解くと議論に参加できます。