$$\vec F =xy^2 \hat i +y x^2 \hat j$$
My attempt:
$$P=U_{x}=xy^2$$
$$Q=U_{y}=x^2y$$
$$\Longrightarrow U=\int P dx=\frac{x^2}{2}y+C(y)$$
$$ U_{y}=\frac{x^2}{2}+C'(y)=Q=x^2y$$
$$\Longrightarrow \boxed{U=\frac{x^2}{2}y+-\frac{y^2}{2}x^2+C(y)}$$
Is it correct?
Recall that a potential function of $\mathbf{\vec F}$ is a function $f$ such that $\mathbf{\vec F} = \vec \nabla f$. We recognize that $\frac{\partial U}{\partial y} = \frac{x^2}{2}-yx^2+C'(y) \neq yx^2$ for any choice of $C(y)$, so your answer is unfortunately incorrect.
There is a small mistake in the third line of your computations. We have $$f(x,y) = \int xy^2 \, dx = \frac{1}{2}x^2 \color{red}{y^2} + C(y).$$ Then, $\frac{\partial f}{\partial y}=x^2y + C'(y)=yx^2$ so $C'(y) = 0$. It follows that $C(y) = k$ for some constant $k$. Thus, for any $k$, $f(x,y)= \frac{1}{2}x^2 y^2 + k$ is a potential function for $\mathbf{\vec F}$.