竟然不給我按submit XD 那就算了哈哈哈~~~~~
看了一下Lee 大神,原來有個什麼黑洞理論,真是齁賽雷啊~~~~~~
雖然好像看懂了但是不想寫XD 先醬只~~~
char* reverseParentheses(char* s) {
int len = strlen(s);
char *stack = calloc(len+1, sizeof(char));
int top = -1;
for (int i=0; i<len ; i++)
{
if (s[i]!=')')
{
stack[++top]=s[i];
continue;
}
char *buf = calloc(len, sizeof(char));
int buf_idx = 0;
while (top>=0 && stack[top]!='(')
{
buf[buf_idx++]=stack[top];
top--;
}
top--; //remove the "("
for (int j=0; j<buf_idx; j++)
stack[++top]=buf[j];
free(buf);
}
stack[top+1]='\0';
return stack;
}
沒有留言:
張貼留言