更新时间:2023-11-28 20:45:16
在我看来,这可能是一个非常简单的解决方案:
In my point of view, that could be a pretty simple solution:
def no_more_than_twice_occur?(array)
array.none? { |el| array.count(el) > 2 }
end
no_more_than_twice_occur?(["1", "3", "3", "55", "3", "2"]) # => false
no_more_than_twice_occur?(["20", "10", "20", "10"]) # => true