99 道榆木问题/第 10 道问题/解决方案
外观
解决方案 1:递归版本
runLengthEncode list =
case list of
[] -> []
[ x ] -> [ (x, 1) ]
x :: xs ->
case runLengthEncode xs of
[] -> []
(x', n) :: xs' ->
if x == x' then
(x, n + 1) :: xs'
else
( x, 1 ) :: (x', n) :: xs'