The union of two subgroups is a subgroup if and only if one is contained in the other

Let $H$ and $K$ be subgroups of $G$. Prove that $H \cup K$ is a subgroup if and only if $H \subseteq K$ or $K \subseteq H$.

The $(\Leftarrow)$ direction is clear. To see $(\Rightarrow)$, suppose that $H \cup K$ is a subgroup of $G$ and that $H \not\subseteq K$ and $K \not\subseteq H$; that is, there exist $x \in H$ with $x \notin K$ and $y \in K$ with $y \notin H$. Now we have $xy \in H \cup K$, so that either $xy \in H$ or $xy \in K$. If $xy \in H$, then we have $x^{-1}xy = y \in H$, a contradiction. Similarly, if $xy \in K$, we have $x \in K$, a contradiction. Then it must be the case that either $H \subseteq K$ or $K \subseteq H$.