Intracavity frequency-doubled and single-frequency Ti:sapphire laser with optimal length of the gain medium