Solve the longest parentheses validation problem, ran into various issues in different cases.