<p>You can always leave at any time. The question is whether or not it's polite / appropriate to do so.</p>
<p>For me, it's:
* It's always impolite to leave before class ends; try not to schedule appointments that conflict.
* If the professor goes a little over, you can leave, but it's a nice gesture to stay. However, if you have other appointments / things to get to, those take priority.</p>
<p>The latter case also applies if the professor goes way over, but just remember that a nice gesture is a nice gesture. It's just like how some professors will be nice enough to not start class until everyone arrives, even if it's a couple minutes late. It's nice of them to do that, but not necessary or even to be expected.</p>