Examples

   
() - true
((()() - false
)(() - false
(()())() - true

Solution in Java

            
public boolean parentheses(String s) {
    int count = 0;
    for (int i = 0; i < s.length(); i++ {
        if (s[i].equals(")")) count++;
        if (s[i].equals("(")) count--;
        if (count < 0) return false;
    }
    if (count == 0) return true;
    return false;
}