A characterization of alternating groups