Input 0,1,2 (respectively stands for '(', ')', "()" ) to a linked list, then find the longest subsequence of 2.

```
public int longestValidParentheses(String s) {
int n = s.length();
if(s.length() < 2) return 0;
LinkedList<Integer> list = new LinkedList<>();
int left = 0;
for(char c : s.toCharArray())
{
if(c == '(')
{
list.add(0);
left++;
}
else
{
if(left > 0)
{
list.removeLastOccurrence(0);
list.add(2);
left--;
}
else
{
list.add(1);
}
}
}
int two = 0;
int max = 0;
boolean flag = true;
for(int num : list)
{
if(num == 2)
{
two++;
if(!flag) flag = true;
}
else
{
if(flag)
{
max = Math.max(two, max);
two = 0;
flag = false;
}
}
}
max = Math.max(two, max);
return 2 * max;
}
```