Skip to content

Instantly share code, notes, and snippets.

View alvindera97's full-sized avatar

Nwokolo Godwin Chidera alvindera97

View GitHub Profile
@alvindera97
alvindera97 / genParenthesis.js
Last active January 25, 2023 13:21
Backtracking Solution For LeetCode 22 (Generate Parenthesis)
function generateParenthesis(n) {
result = new Array();
const backtrack = (op, cp, path = "", stack = new Array()) => {
if (op < 0 || cp < 0) {
return;
}
if (stack.length > 1 && stack.at(-1) === ")" && stack.at(-2) === "(") {
stack = stack.slice(0, stack.length - 2);