LeetCode 491. Non-decreasing Subsequences in F#
URL
https://leetcode.com/problems/non-decreasing-subsequences/description/
Code
https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/problems/0491/main.fsx
let findSubSequences (nums: int list) : int list list =
let isNotEmpty = List.isEmpty >> not
let rec findSubSequences' nums acc ret =
match nums with
| [] ->
if isNotEmpty acc && List.tail acc |> isNotEmpty then
Set.add (acc |> List.rev) ret
else
ret
| h :: t ->
let ret' = findSubSequences' t acc ret
match acc with
| [] -> findSubSequences' t (h :: acc) ret'
| prev :: _ ->
if prev <= h then
findSubSequences' t (h :: acc) ret'
else
ret'
findSubSequences' nums [] Set.empty |> Seq.toList