I've found the dimension of $O(n)$ by the following argument and tried to apply it to $U(n)$, but it didn't go well.
my attempt on $O(n)$: define the map $f:M(n,\mathbb{R})\to Sym(n,\mathbb{R})$ by $A\mapsto A^TA$. then since $O(n)$ is the kernel of $f$, by the rank-nullity theorem, $\dim O(n) = \dim M(n,\mathbb{R})-\dim Sym(n,\mathbb{R})=n^2-\frac{n(n+1)}{2}=\frac{n(n-1)}{2}$.
for $U(n)$, define the map $g:M(n,\mathbb{C})\to Sym(n,\mathbb{C})$ by $A\mapsto A^*A$. then since $U(n)$ is the kernel of $g$, by the rank-nullity theorem, $\dim U(n) = \dim M(n,\mathbb{C})-\dim Sym(n,\mathbb{C})=2n^2-n(n+1)=n(n-1)$.
but in fact $\dim U(n) = n^2$ according to the wiki. where did I miss $n$?
The problem is that you're off on the dimension of what you're calling $Sym(n, \mathbb{C})$ (Hermitian matrices). The complex-conjugate symmetry forces the diagonal to have real entries! So $$\begin{bmatrix} i & 0 \\ 0 & 0 \\ \end{bmatrix}, \begin{bmatrix} 0 & 0 \\ 0 & i \\ \end{bmatrix} $$ are $2$ linearly independent elements that you overcount in $Sym(2, \mathbb{C})$.
In general, in your count of $Sym(n, \mathbb{C})$, generalizing from the count of the dimension of $Sym(n, \mathbb{R})$, you are apparently counting $n$ purely real matrices having exactly one nonzero part on the diagonal, as well as $n$ purely complex matrices having exactly one nonzero part on the diagonal (and similarly for $2n(n-1)$ other non-diagonal matrices, for which there's no problem with the count). Nix the $n$ purely complex diagonal basis elements and then your count is solid.