알고리즘 공부
22. Generate Parentheses
Sense.J
2020. 8. 24. 23:08
https://leetcode.com/problems/generate-parentheses/
Generate Parentheses - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
/**
* @param {number} n
* @return {string[]}
*/
var generateParenthesis = function(n) {
const res = [];
const find = function( p_open, p_close, p_str )
{
if( p_open < n )
find( p_open+1, p_close, p_str.concat('(') );
if( p_close < p_open )
find( p_open, p_close+1, p_str.concat(')') );
if( !(p_open - n) && !(p_open - p_close) )
res.push( p_str );
}
find( 0, 0, '' );
return res;
};