My java solution without using stack


  • -4
    P
    public boolean isValid(String s) {
            int i = 0;
            int len = s.length()/2; 
            if (s.length()%2 != 0 || s.isEmpty() || s == null){
                return false;
            }else{
                for (;i < len; i++){
                    s = s.replaceAll("\\(\\)|\\[\\]|\\{\\}","");
                }
                return s.isEmpty();
            }
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.