2016-07-01 75 views

回答

-1
def list=[1,1,1,2,2,2,3,3,1,6,4,6,5,4] 
def countMap=[:] 
list.each{ 
    if(countMap[it]){ 
    countMap[it]=countMap[it]+1 
    }else{ 
    countMap[it]=1 
    } 
} 
3
assert list.countBy { it } == [1:4, 2:3, 3:3, 4:2, 9:1, 6:2] 
相關問題