implement bracketToPalin using recursion