给定一个只包含 '(' 和 ')' 的字符串,找出最长的包含有效括号的子串的长度。
示例1
输入
"(()"
输出
2
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @return int整型 */ public int longestValidParentheses (String s) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @return int整型 */ int longestValidParentheses(string s) { // write code here } };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param s string字符串 # @return int整型 # class Solution: def longestValidParentheses(self , s ): # write code here
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @return int整型 */ function longestValidParentheses( s ) { // write code here } module.exports = { longestValidParentheses : longestValidParentheses };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param s string字符串 # @return int整型 # class Solution: def longestValidParentheses(self , s ): # write code here
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @return int整型 */ func longestValidParentheses( s string ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @return int整型 */ int longestValidParentheses(char* s ) { // write code here }
"(()"
2