[find matching parenthesis]找到字符串中每个对称括号的位置。对于不对称的 () 会忽略 #python #string
✓ Published0🌍 Public
SShawn91
Last edited Jan 25, 2019
Created on Jan 3, 2019
This example visualizes the positions of matching parentheses in a string by mapping each opening parenthesis to its corresponding closing parenthesis. It shows how a stack-based algorithm can track nesting, returning a dictionary where keys are indices of `(` and values are indices of the matching `)`. Asymmetric parentheses are ignored. The code uses Python’s built-in `enumerate` to iterate through characters, a list `pstack` as a stack, and a dictionary `toret` to store results. No external libraries or rendering are involved; the output is a plain data structure.
AI-generated description