Spectral condition for hamiltonicity of a graph