Shohei Yoshida
Shohei Yoshida's Blog

Follow

Shohei Yoshida's Blog

Follow

LeetCode 1470. Shuffle the Array in F#

Shohei Yoshida's photo
Shohei Yoshida
·Feb 6, 2023·

1 min read

URL

Shuffle the Array - LeetCode

Code

https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/problems/1470/main.fsx

let shuffle (nums: int list) (n: int) : int list =
    (List.take n nums, List.skip n nums)
    ||> List.zip
    |> List.fold (fun acc (x, y) -> y :: x :: acc) []
    |> List.rev
 
Share this