null
第 10 级
Where is my problem ?
正在讨论
评论 (1)
- 受欢迎
- 新
- 旧
你必须先登录才能发表评论
Gellert Varga
8 九月 2021, 16:54
This is your code. The only difference is that it's in a clear format here. Now anybody can clearly see what a block of code contains and where it ends.
And now we can talk about it because we have line numbers too.
(In the next case please if you click the "help" button on top: Do not copy and paste code, just make sure "attach my solution" button is selected.)
line 25: no internal (nested) loop required. It is unnecessary to put the array in ascending or descending order, it is not a requirement now.
You just need one loop where you review the elements and if you find a larger one, you change the 'max' to the appropriate index.
At the end of the loop, the 'max' variable will contain the index where the largest element is in the array.
Then: maximum = num[max];
Because of these changes, '.length-2' in line 22 will need to be modified.
Translated with www.DeepL.com/Translator (free)
0