When does entropy equals the optimal code expected length?

In information theory, we know that the entropy is a lower bound for the optimal code expected length. But when does it hold with equality?

Also, is it possible to determine if they are equal by looking at the binary tree formed by the code?