Right fold (functional programming)


  • 0
    C
    removeNthFromEnd :: Int -> [a] -> [a]
    removeNthFromEnd n = snd . foldr go (1, [])
      where go x (k, xs) | k == n = (1+k, xs)
                         | k /= n = (1+k, x:xs)

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.