1021
char * removeOuterParentheses(char * s){
int top = -1,cnt = 0;
for (int i = 0; s[i]; ++i)
{
if(s[i] == '('){
if(cnt != 0) s[++top] = s[i];
cnt++;
}
if(s[i] == ')'){
cnt--;
if(cnt != 0) s[++top] = s[i];
}
}
s[++top] = '\0';
return s;
}
206
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* reverseList(struct ListNode* head){
struct ListNode *p = head;
int a[5000],t = -1;
while(p != NULL)
{
a[++t] = p -> val;
p = p -> next;
}
p = head;
while (p != NULL)
{
p -> val = a[t--];
p = p -> next;
}
return head;
}
20
bool isValid(char * s){
char *stk = (char *)malloc((strlen(s) + 1)*sizeof(char));
int top = 0;
stk[0] = s[0];
for(int i = 1; s[i]; ++i)
{
if(top >= 0)
{
if (stk[top] == '(' && s[i] == ')')
--top;
else if (stk[top] == '[' && s[i] == ']')
--top;
else if (stk[top] == '{' && s[i] == '}')
--top;
else stk[++top] = s[i];
}
else
{
stk[0] = s[i];
top = 0;
}
}
if (top == -1)
return true;
return false;
}