example:
[1,1,1,2,2,3,1,1]
---->
[[1,1,1],[2,2],[3],[1,1]]
顺序不能变
res, mid = [], [] arr = [1,1,1,2,2,3,1,1] arr.each{|i| unless mid.empty? || i == mid.last; res << mid; mid = []; end; mid << i}; res << mid 这样 OK 么?
a = [1,1,1,2,2,3,1,1] a.chunk{|x|x}.map &:last
#2 楼 @luikore 妙~
#2 楼 @luikore 帅气
都不错啊