Count occurrence of an element in Haskell list and return max sequence

前端 未结 2 1508
别那么骄傲
别那么骄傲 2020-12-21 17:43

I have the following code to count the occurrence of an element in a Haskell list:

data Elem = Vanilla | Choco deriving (Eq,Show)
maxStarSeq :: [Elem] ->          


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-21 18:21

    You can use group and maximum

    import Data.List
    maxSeqLength :: Eq a => [a] -> Int
    maxSeqLength [] = 0
    maxSeqLength xs = (maximum . map length . group) xs
    

提交回复
热议问题