Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Longest Valid Parentheses

Problem

Given a string containing only '(' and ')', return the length of the longest valid (well-formed) parentheses substring.

Approach

  • Use a stack to store indices.
  • Initialize the stack with -1.
  • Push indices of '('.
  • For ')', pop from the stack.
  • If the stack becomes empty, push the current index.
  • Otherwise, update the maximum valid length.

Time Complexity

O(n)

Space Complexity

O(n)

Language

Java

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors