Within 10 lines in Python to solve it.
  def longestValidParentheses(self, s):\n        """ as the ")" will not effect the final result, which acts as a dummy  element to\n            make the all th
      def longestValidParentheses(self, s):\n        """ as the ")" will not effect the final result, which acts as a dummy  element to\n            make the all the  original elements of s equivalently, \n            otherwise the first element needs to be dealt with separately. \n        """ \n        s = ")" + s  \n        stack, ans = [], 0\n        for index in xrange(len(s)):\n          element = s[index]\n          if element == ")" and stack and stack[-1][1] == "(":\n            stack.pop()\n            ans = max(ans, index - stack[-1][0])\n          else:\n            stack.append((index, element))\n        return ans
['Python']