Skip to content

Latest commit

 

History

History
12 lines (9 loc) · 724 Bytes

README.md

File metadata and controls

12 lines (9 loc) · 724 Bytes

Brackets Validation in C++

This program verifies that a string of brackets are valid (i.e. every closing bracket has a opening bracket to match).

Steps

  1. Take in a string of brackets
  2. Check the length of the string, if the length is odd we return false. Brackets come in pairs so the length should always be an even number.
  3. Remove every "{}","[]", or "()" substring within the brackets string
  4. Repeat above until 1 of the 2 following conditions appears
  • The length of the string hits 0. Every bracket has been matched, therefore the string is valid and we return true.
  • The length of the string stays the same over 2 rounds. We can't match some brackets, therefore the string is invalid and we return false