Ad
  • Custom User Avatar

    I could add an additional condition that is AND in the loop which is 0 > openBracesCtr.

    Something like this:
    for(auto i = index+1; i < str.size() && 0 > openBracesCtr; ++i)
    {
    //same as before, but break can now be removed.
    }

    Btw, in my opinion both solutions have similar performance. I guess it's for coders preference on which is more reable. Anyways, thanks for the suggestion. It's good to think a way in tweaking existing solutions. :)

  • Custom User Avatar

    Most compilers will optimize the code so that size() isn't called every iteration. In theory, you are correct, though.

    Suppose size_t i instead of int i would be more correct as well. Iterators probably could have a case here.