# Walking through bracket sequence validation (part 9a8e)

Разберём задачу, которая встречается практически в каждом учебнике по программированию.

## Задача

Проверить, правильно ли расставлены скобки в строке из символов `()[]{}`.

## Решение

```python
def is_balanced(s: str) -> bool:
    pairs = {')': '(', ']': '[', '}': '{'}
    stack = []
    for ch in s:
        if ch in '([{':
            stack.append(ch)
        elif ch in pairs:
            if not stack or stack.pop() != pairs[ch]:
                return False
    return not stack


print(is_balanced("([]{})") )
```

## Как это работает

Это классическое применение стека: открывающая скобка кладётся наверх, закрывающая сверяется с вершиной. Если в конце стек пуст — последовательность верна.

## Пример работы

```text
True
```

## Сложность

O(n) по времени, O(n) по памяти в худшем случае.


Это решение удобно как отправная точка для экспериментов: попробуйте изменить входные данные и проследить за поведением кода.

**Читайте также:**

[строке](https://vit.ac.in/wp-content/uploads/event-manager-uploads/event_banner/2026/10/ms-sethi-onlyfans-videos-8d1e19.pdf) · [Проверить](https://discuss.tchncs.de/post/65440183) · [программированию](https://hey.xyz/posts/1hm2kqf2gj6yx43jst) · [встречается](https://rentry.co/t5yex6tt) · [pairs[ch](https://dev.to/valentina_silvaferreira_/nieskolko-rieshienii-rieshieniia-prostoi-zadachi-chisla-fibonachchi-48da) · [изменить](https://paste.rs/QUY5r) · [кладётся](https://dev.to/valentina_silvaferreira_/rassmatrivaiem-klassichieskuiu-zadachu-provierka-anaghramm-geg) · [худшем](https://discuss.tchncs.de/post/65440465) · [каждом](https://momste.rs/youngtube+starsessions?f=instapaper) · [случае](https://artofhosting.org/wp-content/uploads/event-manager-uploads/event_banner/2026/10/starsessions-maisie-994f14.pdf) · [конце](https://discuss.tchncs.de/post/65446304) · [символов](https://radicle.network/nodes/seed.pipapo.org/rad%3Az2sRtioXKZ9SGH62Rs5BBv8977Vmq/issues/508b513ee499431fe7c54fe9e2402359d461f036) · [последовательность](https://calturin.com/crooked-throne-part-2?f=instapaper) · [которая](https://juliaroux716.overblog.fr/2026/10/post-0.html) · [верна](https://hey.xyz/posts/1tgbyjg039thhqk2yrb) · [данные](https://gitlab.com/chuongnhuhoa/trusrewre/-/blob/main/articles/average-oshibki-mvg1vqcw.md) · [попробуйте](https://hey.xyz/posts/a22kcbgj5qkz3xw9mf) · [учебнике](https://dev.to/valentina_silvaferreira_/rieshaiem-i-tiestiruiem-shifr-tsiezaria-59g) · [скобка](https://paper.wf/verahoffmann79log/desahan-enak-pacar) · [отправная](https://cultmtl.com/wp-content/uploads/event-manager-uploads/event_banner/2026/10/duygu-fdik-if-a-96804d.pdf) · [Пример](https://articlescad.com/jigglygirls-386872.html) · [памяти](https://cultmtl.com/wp-content/uploads/event-manager-uploads/event_banner/2026/10/dwemra-8c7ee7.pdf)

