We analyze both the s- and p-wave collision induced frequency shifts and propose a over-$pi$ pulse scheme to cancel the shifts in optical lattice clocks interrogated by a Rabi pulse. The collisional frequency shifts are analytically solved as a function of the pulse area and the inhomogeneity of the Rabi frequencies. Experimentally measured collisional frequency shifts in an Yb optical lattice clock are in good agreement with the analytical calculations. Based on our analysis, the over-$pi$ pulse combined with a small inhomogeneity below 0.1 allows a fractional uncertainty on a level of $10^{-18}$ in both Sr and Yb optical lattice clocks by canceling the collisional frequency shift.