LeetCode 1190. Reverse Substrings Between Each Pair of Parentheses in F#
URL
Reverse Substrings Between Each Pair of Parentheses - LeetCode
Code
open System
let reverseParentheses (s: string) : string =
let rec reverseParentheses' (cs: char list) acc =
match cs with
| [] -> List.rev acc, []
| h :: t ->
match h with
| '(' ->
let v, rest = reverseParentheses' t []
reverseParentheses' rest (v @ acc)
| ')' -> List.rev acc, t
| c -> reverseParentheses' t (c :: acc)
reverseParentheses' (Seq.toList s) [] |> fst |> String.Concat