forked from lolosssss/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path22_generate_parentheses.c
65 lines (51 loc) · 1.27 KB
/
22_generate_parentheses.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Description : Generate Parentheses
* Given n pairs of parentheses, write a function to generate all
* combinations of wellformed parentheses.
* For example, given n = 3, a solution set is:
* "((()))", "(()())", "(())()", "()(())", "()()()"
* Author : Evan Lau
* Date : 2016/03/03
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
void foo(int l, int r, char **res, char *stack,int n, int top)
{
}
/**
* Return an array of size *returnSize.
* Note: The returned array must be malloced, assum caller calls free().
*/
char** generateParentheses(int n, int* returnSize)
{
char **res = NULL;
char stack[2 * n];
int top = 0;
res = (char **)malloc(sizeof(char *) * 128);
for (int i = 0; i < 128; i++)
{
res[i] = (char *)malloc(sizeof(char) * (n * 2 + 1));
}
*returnSize = 0;
foo(n, n, res, stack, n, top);
return res;
}
int main(void)
{
char **res = NULL;
int size = 0;
res = generateParentheses(5, &size);
printf("size = %d\n", size);
for (int i = 0; i < size; i++)
{
printf("%s\n", res[i]);
}
for (int i = 0; i < size; i++)
{
free(res[i]);
}
free(res);
res = NULL;
return 0;
}