2013-07-10 86 views

回答

6
# As simple as possible: 
not_unique == not_unique.uniq 

# or perhaps 
not_unique.size == not_unique.uniq.size 
+0

甚至沒有想到那個。謝謝! – Andrew

1
require 'set' 
arr = [1,2,3] 
arr.to_set.length == arr.length 

或Larsenal指出:

arr.uniq == arr 
3
array & array == array 

是另一種選擇。

相關問題