我这一题写了好多测试都过了,但是提交就过10%,感觉自己陷入了思路死角,求各位大佬指点

import java.util.Scanner;
import java.util.Stack;
/**
 * @Author: 
 * @Date: Created in 18:51 2018/4/9
 */
public class Test03 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n  = sc.nextInt();
        sc.nextLine();
        for (int j = 0; j < n; j++) {
            String str = sc.nextLine();
            Stack<Character> stack = new Stack<>();
            stack.push(str.charAt(0));
            for (int i = 1; i < str.length(); i++) {
                if (str.charAt(i) == '(') {
                    stack.push(str.charAt(i));
                } else if (str.charAt(i)==')'){
                    if (!stack.isEmpty()) {
                        if (stack.peek().equals('('))
                            stack.pop();
                        else
                            stack.push(str.charAt(i));
                    } else
                        stack.push(str.charAt(i));
                }
            }
            if (stack.size() == 2) {
                char c = stack.pop();
                if (c=='(' && stack.pop().equals(')'))
                    System.out.println("Yes");
                else
                    System.out.println("No");
            } else
                System.out.println("No");
        }
    }
}