给定一个整型数组arr,请打印其中出现次数大于一半的数,如果没有这样的数,请输出-1。
示例1
输入
[11,7,5,7,7]
输出
7
示例2
输入
[2,2,3,3]
输出
-1
加载中...
import java.util.*; public class Solution { /** * * @param arr int整型一维数组 the array * @return int整型 */ public int findNum (int[] arr) { // write code here } }
class Solution { public: /** * * @param arr int整型vector the array * @return int整型 */ int findNum(vector
& arr) { // write code here } };
# # # @param arr int整型一维数组 the array # @return int整型 # class Solution: def findNum(self , arr ): # write code here
/** * * @param arr int整型一维数组 the array * @return int整型 */ function findNum( arr ) { // write code here } module.exports = { findNum : findNum };
# # # @param arr int整型一维数组 the array # @return int整型 # class Solution: def findNum(self , arr ): # write code here
package main /** * * @param arr int整型一维数组 the array * @return int整型 */ func findNum( arr []int ) int { // write code here }
/** * * @param arr int整型一维数组 the array * @param arrLen int arr数组长度 * @return int整型 */ int findNum(int* arr, int arrLen ) { // write code here }
[11,7,5,7,7]
7
[2,2,3,3]
-1