You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 假设数组为纯数字数组
function getHalfChanceNumber(arr) {
if (!arr) return 0
if (!arr.length) return 0
var len = arr.length
var hasCountHalf = false
var countN = {}
for (var i = 0 ; i < len; i++) {
countN[arr[i]] = countN.hasOwnProperty(arr[i]) ? ++countN[arr[i]] : 1
if (countN[arr[i]] > len / 2) {
hasCountHalf = true
return arr[i]
}
}
if (!hasCountHalf) return 0
}
如题
The text was updated successfully, but these errors were encountered: