<filename>Valid Parentheses.py
def checkEqual(s):
    count1 = 0
    count2 = 0
    count3 = 0
    for i in range(len(s)):
        if s[i] == '(':
            count1 += 1
        elif s[i] == ')':
            count1 -= 1
        elif s[i] == '[':
            count2 += 1
        elif s[i] == ']':
            count2 -= 1
        elif s[i] == '{':
            count3 += 1
        elif s[i] == '}':
            count3 -= 1
    
    if count1 == 0 and count2 == 0 and count3 == 0:
        return True
    return False

def checkConsecutive(s):
    while len(s) != 0: 
        for i in range(len(s)):
            if s[i] == ')':
                if s[i-1] != '(' or i-1 < 0:
                    return False
                else:
                    s = s[:i-1] + s[i+1:]
                    break
            if s[i] == ']':
                if s[i-1] != '[' or i-1 < 0:
                    return False
                else:
                    s = s[:i-1] + s[i+1:]
                    break
            if s[i] == '}':
                if s[i-1] != '{' or i-1 < 0:
                    return False
                else:
                    s = s[:i-1] + s[i+1:]
                    break
    return True
    
class Solution:
    def isValid(self, s: str) -> bool:
        if len(s) % 2 != 0:
            return False
        
        if checkEqual(s) and checkConsecutive(s):
            return True
        return False

class Solution:
    def isValid(self, s: str) -> bool:
        stack = [0 for i in range(100000)]
        flag = -1
        
        for i in range(len(s)):
            if s[i] == ')':
                if flag >= 0 and stack[flag] == '(':
                    flag -= 1
                else:
                    return False
            elif s[i] == ']':
                if flag >= 0 and stack[flag] == '[':
                    flag -= 1
                else:
                    return False
            elif s[i] == '}':
                if flag >= 0 and stack[flag] == '{':
                    flag -= 1
                else:
                    return False
            else:
                flag += 1
                stack.insert(flag, s[i])
        
        return flag == -1

class Solution:
    def isValid(self, s: str) -> bool:
        stack = []
        flag = -1
        
        for i in range(len(s)):
            if s[i] == ')':
                if flag >= 0 and stack[flag] == '(':
                    flag -= 1
                    stack.pop()
                else:
                    return False
            elif s[i] == ']':
                if flag >= 0 and stack[flag] == '[':
                    flag -= 1
                    stack.pop()
                else:
                    return False
            elif s[i] == '}':
                if flag >= 0 and stack[flag] == '{':
                    flag -= 1
                    stack.pop()
                else:
                    return False
            else:
                flag += 1
                stack.append(s[i])
        
        return flag == -1
<filename>Valid Parentheses.py
def checkEqual(s):
    count1 = 0
    count2 = 0
    count3 = 0
    for i in range(len(s)):
        if s[i] == '(':
            count1 += 1
        elif s[i] == ')':
            count1 -= 1
        elif s[i] == '[':
            count2 += 1
        elif s[i] == ']':
            count2 -= 1
        elif s[i] == '{':
            count3 += 1
        elif s[i] == '}':
            count3 -= 1
    
    if count1 == 0 and count2 == 0 and count3 == 0:
        return True
    return False

def checkConsecutive(s):
    while len(s) != 0: 
        for i in range(len(s)):
            if s[i] == ')':
                if s[i-1] != '(' or i-1 < 0:
                    return False
                else:
                    s = s[:i-1] + s[i+1:]
                    break
            if s[i] == ']':
                if s[i-1] != '[' or i-1 < 0:
                    return False
                else:
                    s = s[:i-1] + s[i+1:]
                    break
            if s[i] == '}':
                if s[i-1] != '{' or i-1 < 0:
                    return False
                else:
                    s = s[:i-1] + s[i+1:]
                    break
    return True
    
class Solution:
    def isValid(self, s: str) -> bool:
        if len(s) % 2 != 0:
            return False
        
        if checkEqual(s) and checkConsecutive(s):
            return True
        return False

class Solution:
    def isValid(self, s: str) -> bool:
        stack = [0 for i in range(100000)]
        flag = -1
        
        for i in range(len(s)):
            if s[i] == ')':
                if flag >= 0 and stack[flag] == '(':
                    flag -= 1
                else:
                    return False
            elif s[i] == ']':
                if flag >= 0 and stack[flag] == '[':
                    flag -= 1
                else:
                    return False
            elif s[i] == '}':
                if flag >= 0 and stack[flag] == '{':
                    flag -= 1
                else:
                    return False
            else:
                flag += 1
                stack.insert(flag, s[i])
        
        return flag == -1

class Solution:
    def isValid(self, s: str) -> bool:
        stack = []
        flag = -1
        
        for i in range(len(s)):
            if s[i] == ')':
                if flag >= 0 and stack[flag] == '(':
                    flag -= 1
                    stack.pop()
                else:
                    return False
            elif s[i] == ']':
                if flag >= 0 and stack[flag] == '[':
                    flag -= 1
                    stack.pop()
                else:
                    return False
            elif s[i] == '}':
                if flag >= 0 and stack[flag] == '{':
                    flag -= 1
                    stack.pop()
                else:
                    return False
            else:
                flag += 1
                stack.append(s[i])
        
        return flag == -1