To reveal the answer, click on the following button:
Well, the last one said that he could not understand what hat is wearing. Since he was able to see both the first and the second and since he knows that at least one wears a red hat, it is certain that the first and second persons do not wear both green hats. At least one of them or both wear red hat.
The second person listens to the third person, so he understands that there are 3 possibilities:
1. Only the first person wears red hat and he wears a green hat
2. They both wear a red hat
3. The first person wears a green hat and he wears a red hat
But he says that he cannot understand what hat he wears. This means that he sees a red hat on the first person, and therefore he cannot be sure if he wears a red hat too or a green. If he had seen a green hat on the first person, he would be sure that he wears a red hat.