Attitude determination is a key technology in aerospace, sailing and land-navigation etc. In the method of double difference phase measurement, it is a crucial topic to solve the carrier phase integer ambiguity, which is shown to be a combination optimization problem, and thus efficient heuristic algorithms are needed. In this paper, we propose a discrete particle swarm optimization (DPSO)-based solution which aims at searching for the optimal integer ambiguity directly without decorrelation of ambiguity, and computing the baseline vector consequently. A novel flat binary particle encoding approach and corresponding revision operation are presented. Furthermore, domain knowledge is incorporated to significantly improve the convergence rate. Through extensive experiments, we demonstrate that the proposed algorithm outperforms a classic algorithm by up to 80% in time efficiency with solution quality guaranteed. The experiment results show that this algorithm is efficient, robust, and suitable for dynamic attitude determination.