Ad

This kumite determines if a string only has closed parentheses. The goal is to optimize the runtime of the program. Currently, it runs in about 2.8 seconds through the test suite. Can it be better?

bool isBalanced(const std::string& s) {
  int count = 0;
  for (size_t i = 0; i < s.length(); i++) {
    if (s[i] == '(') {
      count++;
    }
    if (s[i] == ')') {
      if (count <= 0) { return false; }
      count--;
    }
  }
  return true;
}