也就是說 該數字出現的次數比其餘全部數字出現次數的和還要多。 所以能夠保存兩個值,一個數字,一個次數。 遍歷時 一、若是數字相同,count++ 二、若是count == 0 count = 1 number替換 三、若是不相同 count-- int main(){ int array[] = {3, 2, 3, 1, 3, 4}; int number = array[0], count = 0; for (int i = 1; i < 6; i++){ if (count == 0){ count = 1; number = array[i]; } if (array[i] != number){ count--; } else{ count++; } } cout << number << " " << count << endl; system("pause"); return 0; }