gitrepo_20 / 10-week-algorithm-excercise-master /OneQuestionPerDay /1021 /remove_outermost_parentheses.py
Download 10-week-algorithm-excercise-master/OneQuestionPerDay/1021/remove_outermost_parentheses.py from Dorothydu/gitrepo_20: direct link, hf CLI and curl.
- Browser
- Download file 394 Bytes
-
https://huggingface.co/datasets/Dorothydu/gitrepo_20/resolve/main/10-week-algorithm-excercise-master/OneQuestionPerDay/1021/remove_outermost_parentheses.py
- Command line
-
hf download hf://datasets/Dorothydu/gitrepo_20/10-week-algorithm-excercise-master/OneQuestionPerDay/1021/remove_outermost_parentheses.py
-
curl -L -o remove_outermost_parentheses.py https://huggingface.co/datasets/Dorothydu/gitrepo_20/resolve/main/10-week-algorithm-excercise-master/OneQuestionPerDay/1021/remove_outermost_parentheses.py
394 Bytes
| class Solution: | |
| def removeOuterParentheses(self, S: str) -> str: | |
| counter = 0 | |
| start = 0 | |
| strs = [] | |
| for i, c in enumerate(S): | |
| if c == "(": | |
| counter += 1 | |
| else: | |
| counter -= 1 | |
| if counter == 0: | |
| strs.append(S[start + 1:i]) | |
| start = i + 1 | |
| return "".join(strs) | |