Đề bài
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.
Ràng buộc
-1,000,000,000 ≤ a, b, c ≤ 1,000,000,000
Ví dụ
Đầu vào:
a = 3
b = 9
c = 4
Kết quả mong đợi:
expected = 9
Đầu vào:
long long a = 3;
long long b = 9;
long long c = 4;
Kết quả mong đợi:
long long expected = 9;
Đầu vào:
long a = 3;
long b = 9;
long c = 4;
Kết quả mong đợi:
long expected = 9;
Giải thích
9 is greater than both 3 and 4.
Đầu vào:
a = -5
b = -2
c = -2
Kết quả mong đợi:
expected = -2
Đầu vào:
long long a = -5;
long long b = -2;
long long c = -2;
Kết quả mong đợi:
long long expected = -2;
Đầu vào:
long a = -5;
long b = -2;
long c = -2;
Kết quả mong đợi:
long expected = -2;
Giải thích
-2 appears twice and is the largest value.
Hướng tiếp cận
Hãy tự thử trước, sau đó mở từng gợi ý một.
Gợi ý 1
Compare the numbers pair by pair to identify the largest one.
Gợi ý 2
A few conditional checks are enough; no search structure is needed.
Gợi ý 3
Be careful with equal values, since ties should still return the correct largest number.
Độ phức tạp mong đợi
O(1) time, O(1) extra space
Tham khảo
Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.