// Given an integer array nums, return the third distinct maximum number in this array. If the third maximum does not exist, return the maximum number.
function thirdMax($nums) {
    $nums = array_unique($nums);  // built-in function that removes duplicated values in array
    sort($nums);
    $count = count($nums);
    if ($count >= 3) {
	array_pop($nums);
	array_pop($nums);
    }
    return end($nums); // built-in function that returns the last element of array
}
echo thirdMax([2, 2, 3, 1]);
by Luka Khitaridze
2 years ago
PHP
Array
0
Pro tip: use ```triple backticks around text``` to write in code fences