Advertisement
lazar955

Untitled

Oct 24th, 2023
830
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.40 KB | None | 0 0
  1. string
  2.  
  3.     helper(n,0,0,"", &res)
  4.  
  5.     return res
  6. }
  7.  
  8. func helper (n int, open int, close int, currentStr string, res *[]string) {
  9.     if open == n && close == n {
  10.         *res = append(*res,currentStr)
  11.         return
  12.     }
  13.  
  14.     if open < n {
  15.         helper(n, open + 1, close, currentStr + "(", res)
  16.     }
  17.     if open > close {
  18.         helper(n,open, close + 1, currentStr+ ")", res)
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement