Skip to main content
2 of 2
added 202 characters in body
Alan
  • 14.1k
  • 22
  • 42
Split[{1, 1, 2, 1, 1, 1, 2, 2, 1, 2, 1}, SameQ] /. {x : {1 ..} :> Length[x]} /. {x : {2 ..} :> Sequence @@ ConstantArray[0, Length[x] - 1]} 

Note: your example has no divider as the first or last element. If an initial or final sequence of 1s can be empty -- that is, if the first or last element can be a bin divider -- the answer changes

Alan
  • 14.1k
  • 22
  • 42