Q:

Verify the number of opening and closing brackets

Need to write a function that checks the validity of the placement of braces in a row. 
If the opening parenthesis corresponds to much the same closing, the function should return true. 
Example of the input string: "(())) ()) ()"
Posted two variants of solutions.  Which one is better, and there is a better way to solve the problem? 
1:
bool parenthesis(char myString[80]) {
    int k = 0;
    for (int i = 0; myString[i]; ++i) {
        if (myString[i] == '(')
            k++;
        if (myString[i] == ')')
            k--;
    }
    if (k == 0)
        return true;
    else
        return false;
}

2:
#include <algorithm>
#include <iostream>
#include <string>

int main()
{
    std::string str = "(()))())()";
    std::cout << std::boolalpha
              << (std::count(str.begin(), str.end(), '(') == 
                  std::count(str.begin(), str.end(), ')') && *str.begin() ==
                  '(' && *str.rbegin() == ')')
              << std::endl;
}

A:

This is easy to do by just adding one for (, subtracting one for ), while taking care the sum never goes negative.  At the end it has to be zero. 

A:

Both seem not optimal as they would validy strings as
()))((()

I would probably do the counting thing but check additionally that the number is always non-negative. 
bool validate_parantheses(const std::string& str)
{
    int count = 0;
    for(char c : str)
    {
        if(c == '(')
            count++;
        else if(c == ')')
            count--;
        if(count < 0)
            return false;
    }
    return count == 0;
}    

