Question d’entretien chez SentinelOne

Valid Parenthesis in an mathematical expression.

Réponses aux questions d'entretien

Utilisateur anonyme

10 mai 2024

Used stack

Utilisateur anonyme

11 août 2024

class Solution: def isValid(self, s: str) -> bool: stack = [] paranthesis_exp = { "}" : "{", "]" : "[", ")" : "(" } for char in s: if char in paranthesis_exp.values(): stack.append(char) elif char in paranthesis_exp.keys(): if not stack or stack[-1] != paranthesis_exp[char]: return False stack.pop() return len(stack) == 0