1. 程式人生 > >LeetCode - Parentheses 總結

LeetCode - Parentheses 總結

DFS

22. Generate Parentheses

301. Remove Invalid Parentheses (BFS)

 

Stack

20. Valid Parentheses

32. Longest Valid Parentheses (also dp)

tip:

1. stack裡面存'('的index instead of the character itself

2. validity <- use the stack

 

divide and conquer

241. Different Ways to Add Parentheses

 

string

856. Score of Parentheses

Notes:

1.如果只存在一種parentheses可以直接用left and right count來表示