Here is the Python code to solve the problem using a set and sorting:

```
def thirdMax(nums):
    unique_nums = sorted(set(nums), reverse=True)
    return unique_nums[2] if len(unique_nums) >= 3 else unique_nums[0]
```

Explanation: We create a set from the input array `nums` to get rid of duplicates. Then, we sort the resulting set in descending order. If the set has at least 3 distinct elements, we return the third element. Otherwise, we return the maximum element, which is the first element in the sorted set.
### Instruction:
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.

### Response:
