Write programming code to find the second largest number in an array.
Return the second largest distinct value, or None if fewer than two distinct values exist. Implement the function for an integer array, preserving O(n) time and O(1) extra space. Examples: [3, 1, 4, 2] returns 3; [5, 5] returns None. Constraints: 2 <= len(nums) <= 10^4 and values are integers.
def second_largest(nums):