-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathday20.sol
More file actions
30 lines (26 loc) · 740 Bytes
/
Copy pathday20.sol
File metadata and controls
30 lines (26 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;
contract Day20 {
function secondMax(int256[] memory array, uint256 size)
public
pure
returns (int256)
{
for (uint256 step = 0; step < size - 1; ++step) {
int256 swapped = 0;
for (uint256 i = 0; i < size - step - 1; ++i) {
if (array[i] > array[i + 1]) {
int256 temp;
temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;
swapped = 1;
}
}
if (swapped == 0) {
break;
}
}
return array[size -2];
}
}