------
## 最终结论
```python
def calculate(s: str) -> int:
    stack = []
    current_number = 0
    current_result = 0
    sign = 1  # 1 represents '+', -1 represents '-'

    for char in s:
        if char == ' ':
            continue
        elif char.isdigit():
            current_number = current_number * 10 + int(char)
        elif char in '+-':
            current_result += sign * current_number
            current_number = 0
            sign = 1 if char == '+' else -1
        elif char == '(':
            stack.append(current_result)
            stack.append(sign)
            current_result = 0
            sign = 1
        elif char == ')':
            current_result += sign * current_number
            current_result *= stack.pop()  # sign before the parentheses
            current_result += stack.pop()  # result before the parentheses
            current_number = 0

    current_result += sign * current_number
    return current_result
```