Write an algorithm to efficiently sort a binary array.
Use the function signature def sort_binary_array(nums):. The input is a list containing only 0 and 1; return the same list sorted in ascending order. Aim for O(n) time and O(1) extra space.
def sort_binary_array(nums):