now plz help is my solution wrong?
which is identical to the first solution.
There are still the corner cases of $\sin(x) = \sin(3x) = 0$ but you can show that those don't affect the solution.
So both methods are equivalent but the first way is a bit cleaner in my opinion.
The problem with the cotangent solution is that at $x=n\pi$, the contangent functions are undefined and cannot therefore be equal. In the sine solution, $x = n\pi$ is a valid solution.
If you are going to use the cotangent derivation, then you have to recognise that you have divided by both $\sin x$ and $\sin 3x$. This is not a valid operation when these expressions are equal to zero, so you have to validate those values of $x$ separately.