π
Find Maximum
Find Maximumμ¬μ λ°°μ΄ +10pts
Problem
Write a function that returns the largest number in an array.
Examples
Input:
findMax([1, 5, 3, 9, 2])Output:
9Input:
findMax([-1, -5, -3])Output:
-1Explanation
μ΄ λ¬Έμ λ **Math.max()** ν¨μμ **μ€νλ λ μ°μ°μ(...)**μ μ‘°ν©μ νμ΅ν©λλ€. **Math.max() ν¨μ** Math.max()λ μ λ¬λ μΈμ μ€ κ°μ₯ ν° κ°μ λ°νν©λλ€. νμ§λ§ λ°°μ΄μ μ§μ λ°μ§λ μμ΅λλ€: - `Math.max(1, 5, 3)` β 5 (μ μ λμ) - `Math.max([1, 5, 3])` β NaN (λ°°μ΄μ μ§μ μ²λ¦¬ λΆκ°) **μ€νλ λ μ°μ°μ (...)** μ€νλ λ μ°μ°μλ λ°°μ΄μ κ°λ³ μμλ‘ "νΌμ³μ€λλ€": - `...[1, 5, 3]`μ `1, 5, 3`κ³Ό κ°μ΅λλ€ - `Mat...
View detailed explanation βKey Concepts
Math.max() ν¨μ μ€νλ λ μ°μ°μ (...) λ°°μ΄ νΌμΉκΈ° μ΅λκ° μκ³ λ¦¬μ¦
Time: O(n) Space: O(n)
solution.js
Ctrl + Enter
Run tests to see results here.