郭加磊數(shù)據(jù)基礎(chǔ)入門
// 左右兩側(cè)數(shù)組中出現(xiàn)次數(shù)最多的數(shù)字不相同
? ? ? ?int leftCount = getCount(nums, start, mid - 1, left);
? ? ? ?int rightCount = getCount(nums, mid, end, right);
? ? ? ?if (leftCount > rightCount) {
? ? ? ? ? ?return left;
? ? ? ?}
? ? ? ?return right;
? ?}
? ?public int getCount(int[] nums, int start, int end, int target) {
? ? ? ?return (int) IntStream.range(start, end + 1).filter(i -> nums[i] == target).count();
? ?}}
標(biāo)簽: