While other answers are correct, they don't explain the solution.
I am assuming your question is about the expected number of coin tosses. Let $X$ be the discreet random variable that is the number of throws until two of the same coin are observed. Your question is asking about the expected value of $X$ i.e. $E(X)$.
It is evident $P(X=1)= 0$.
So what is $P(X=2)$? In other words, what is the probability the game terminates after two tosses? Well whatever the first coin was, the probability of the second toss being the same is $1 \over 2$ So $P(X=2) = \frac{1}{2}$.
Similarly consider $P(X=3)$ which is the probability the game terminates after $3$ tosses. Whatever is tossed first, there is a $1 \over 2$ chance that the second throw is different and then a $1 \over 2$ chance the third throw is the same as the second. So the total probability is $P(X=3) = \frac{1}{ 2^2}$.
Continuing the pattern, we get that the probability of the game terminating after $n$ throws, for $n \geq 2$, is $P(X=n) = \frac{1}{2^{n-1}}$. Alternatively, the probability of the game terminating after $n+1$ throws, for $n \geq 1$, is $P(X=n+1) = \frac{1}{2^{n}}$.
Thus the expected value $E(X)$ is given by:
$$
\begin{align}
E(X) &= \sum_{n = 1}^{\infty}(n+1) \cdot P(X = n+1) \\
&= \sum_{n = 1}^{\infty}(n+1) \cdot \frac{1}{2^{n}} \\
&= \sum_{n = 1}^{\infty}\frac{n}{2^n} + \sum_{n = 1}^{\infty}\frac{1}{2^{n}}
\end{align}
$$
We know the right term: $\sum_{n = 1}^{\infty}\frac{1}{2^{n}}$ is a geometric progression and is given by:
$$
\begin{align}
\sum_{n = 1}^{\infty}\frac{1}{2^{n}} &= \frac{1}{2} \cdot \frac{1}{1+ \frac{1}{2}} \\
&= 1
\end{align}
$$
The other sum, $\sum_{n = 1}^{\infty}\frac{n}{2^n}$ is slightly harder but we can do a bit of trickery. Let us call the sum $S$ and consider $\frac{S}{2}$:
$$
\begin{align}
S &= \sum_{n = 1}^{\infty}\frac{n}{2^n} \\
\frac{S}{2} &= \sum_{n = 1}^{\infty}\frac{n}{2^{n+1}} = \sum_{n = 1}^{\infty}\frac{n-1}{2^n} \\
\end{align}
$$
Note how we shifted the indices in the second line for easier manipulation. Subtracting the two lines gives:
$$
\begin{align}
S - \frac{S}{2} = \frac{S}{2} &= \sum_{n = 1}^{\infty}\frac{n}{2^n} - \sum_{n = 1}^{\infty}\frac{n-1}{2^n} \\
&= \sum_{n = 1}^{\infty}\frac{n}{2^n} - \frac{n-1}{2^n} \\
&= \sum_{n = 1}^{\infty}\frac{1}{2^n} \\
&= 1
\end{align}
$$
and so $\frac{S}{2} = 1$ giving $S = 2$.
So in total:
$$
\begin{align}
E(X) &= \sum_{n = 1}^{\infty}\frac{n}{2^n} + \sum_{n = 1}^{\infty}\frac{1}{2^{n}} \\
&= 2 + 1 = 3\\
\end{align}
$$
Addendum (thanks to @bof)
An alternative, and excellent explanation offered by @bof is that:
$$
E(X)=\sum_{k=1}^\infty P(X\ge k)=1+1+\frac12+\frac14+\frac18+\cdots=3.
$$
To see why this is, consider the following (quoted from bof's comment):
Since $X$ takes only positive integer values,
$$
\begin{array}
\ P(X\ge1)= &P(X=1)&+ & P(X=2) & + & P(X=3)+\cdots \\
P(X\ge2)= & & & P(X=2) & + & P(X=3)+\cdots \\
P(X\ge3)= & & & & & P(X=3)+\cdots \\
\end{array}
$$
Adding by columns:
$$\sum_{k=1}^\infty P(X\ge k)=P(X=1)+2P(X=2)+3P(X=3)+\cdots=E(X).$$
In other words: Let the "indicator variable" $X_k=1$ if the kth toss is needed (no HH or TT in first $k-1$ tosses), $X_k=0$ otherwise; then $X=\sum_{k=1}^\infty X_k$ so
$$
E(X)=\sum_{k=1}^\infty E(X_k)=\sum_{k=1}^\infty P(X\ge k).
$$