Solution (source code)

= Solution

Let $u=\Re f$, and suppose $u$ has a local maximum at $z_0\in U$. Choose $R>0$ such that the closed disk $\overline{D(z_0,R)}$ lies in $U$ and $u(z)\leq u(z_0)$ throughout it. Start <planar Brownian motion> $B$ at $z_0$, and for $0<r<R$ let $\tau_r$ be its first exit from $D(z_0,r)$.

By part (a) and <Itô formula>, $u(B_{t\wedge\tau_r})$ is a <local martingale>; boundedness of $u$ on the compact disk makes it a true bounded <martingale>. The exit time is finite <almost surely>. One direct check applies the same formula to $|B_{t\wedge\tau_r}-z_0|^2$, giving $2\mathbb E(t\wedge\tau_r)=\mathbb E|B_{t\wedge\tau_r}-z_0|^2\leq r^2$. Thus $\mathbb E\tau_r\leq r^2/2$.

The <optional stopping theorem>, first at $t\wedge\tau_r$ and then by bounded convergence, gives
$$
u(z_0)=\mathbb E_{z_0}u(B_{\tau_r}).
$$
The exit point is uniformly distributed on the circle: <rotational invariance of planar Brownian motion> about its starting point makes its exit law rotation invariant, and normalized arc length is the unique rotation-invariant probability measure on a circle. Since every boundary value is at most $u(z_0)$, equality of the mean forces every boundary value to equal $u(z_0)$; continuity rules out a strict deficit at any boundary point. This holds for every $0<r<R$, so $u$ is constant on the entire disk.

The <Cauchy-Riemann equations> then give both partial derivatives of $v=\Im f$ equal to zero there. Thus $f$ is constant on that disk. The <identity theorem for holomorphic functions> propagates this constant to the connected component of $z_0$ in $U$. Applying the same Brownian argument to $v$ proves the assertion for the imaginary part as well:
$$
\boxed{\text{A local maximum of }\Re f\text{ or }\Im f\text{ forces }f\text{ to be constant on that component of }U.}
$$
If $U$ is connected, this is constancy on all of $U$. For a disconnected open set the printed global wording needs this qualification: a function taking different constants on two disjoint disks is holomorphic and has local maxima on each disk while not being globally constant.