✅💯🔥Simple Code🚀📌|| 🔥✔️Easy to understand🎯 || 🎓🧠Beats 100%🔥|| Beginner friendly💀💯
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int longestValidParentheses(String s) {\n        int maxi=0;\n        int right = 0;\n        int left=0;\n        for(int i=0; i<s.length(); i++){\n            char ch = s.charAt(i);\n            if(ch==\'(\'){\n                left++;\n            }else if(ch==\')\'){\n                right++;\n            }\n\n            if(left==right){\n                maxi=Math.max(maxi, 2*left);\n            } else if(right>left){\n                right=0;\n                left=0;\n            }\n        }\n        left=0; right=0;\n        for(int i=s.length()-1; i>=0; i--){\n            char ch = s.charAt(i);\n            if(ch==\'(\'){\n                left++;\n            }else if(ch==\')\'){\n                right++;\n            }\n\n            if(left==right){\n                maxi=Math.max(maxi, 2*right);\n            } else if(right<left){\n                right=0;\n                left=0;\n            }\n        }\n\n        return maxi;\n    }\n}\n```\n\n![e78e83d2-3828-4681-96d5-40e225e1d8b0_1699854685.5280945.jpeg](https://assets.leetcode.com/users/images/a9a682ef-8a56-461e-9e1b-7654b114838f_1721590703.0971212.jpeg)
['String', 'Dynamic Programming', 'Stack', 'C', 'Python', 'C++', 'Java']