Sequential numbers in a list haskell

前端 未结 3 1172
清酒与你
清酒与你 2021-01-26 11:55

I am new to haskell and I was attempting a few coding problems that I previously completed for java, however the following problem has me stumped.

Basically the idea is

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-26 12:57

    One way would be to use pattern matching to look for consecutive ones at the head of the list, and advance down the list until you find them, or you run out of elements to look at.

    consecutiveOnes [] = False
    consecutiveOnes (1:1:_) = True
    consecutiveOnes (_:xs) = consecutiveOnes xs
    

提交回复
热议问题