473.Find the Largest of Three Numbers
Easy
Given three integers
a, b, and c, return the largest of the three. If more than one share the largest value, any of them is a correct answer.
The nested if-elseNested If-ElseCombining two comparisons with && inside each branch of an if/else-if/else chain. version checks all three candidates explicitly, one at a time. The running maximumRunning MaximumKeeping a single "best so far" value and updating it by comparing against one new value at a time, instead of comparing everything against everything at once. version never compares three things simultaneously — it reduces the problem to two simple two-value comparisons, which is exactly the technique used to find the largest value in an array of any length.
Example 1:
Input: a = 4, b = 9, c = 2
Output: 9
Example 2:
Input: a = 3, b = 8, c = 5
Output: 8
Example 3:
Input: a = 5, b = 5, c = 5
Output: 5
+ 5 hidden test cases run on Submit.
Constraints:
- ●
-1000 ≤ a ≤ 1000 - ●
-1000 ≤ b ≤ 1000 - ●
-1000 ≤ c ≤ 1000
a =
4
b =
9
c =
2