You start by setting largest
and second_largest
to the largest element value (the first one in this case):
largest = nums[0]
second_largest = nums[0]
Unfortunately, that means the expressions:
nums[i] > largest
nums[i] > second_largest
will never be true, so second_largest
will never change from its initial (largest) value.
If…
Top comments (0)