The charged particles produced in nucleus-nucleus collisions are divided into two parts. One is from the hot and dense matter created in collisions. The other is from leading particles. The hot and dense matter is assumed to expand according to unified hydrodynamics and freezes out into charged particles from a space-like hypersurface with a fixed proper time ofτFO. The leading particles are conventionally taken as the particles which inherit the quantum numbers of colliding nucleons and carry off most of incident energy. The rapidity distributions of the charged particles from these two parts are formulated analytically, and a comparison is made between the theoretical results and the experimental measurements performed in Au-Au and Pb-Pb collisions at the respective BNL-RHIC and CERN-LHC energies. The theoretical results are well consistent with experimental data.