Calculate the inverse of a 2x2 matrix. If the matrix is singular (determinant is zero), return None.
def inverse_2x2(matrix: list[list[float]]) -> list[list[float]]:
a, b = matrix[0]
c, d = matrix[1]
det = a * d - b * c
if det == 0:
return None
inv_det = 1 / det
return [
[d * inv_det, -b * inv_det],
[-c * inv_det, a * inv_det]
]