题解 | #牛群的秘密通信#
牛群的秘密通信
https://www.nowcoder.com/practice/f0047999594d4cd39f85d7347c6941af
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return bool布尔型 */ #include <stdbool.h> #include <time.h> bool is_valid_cow_communication(char* s ) { // write code here char stack[100000] = {0}; int top = -1; while(*s){ if(*s=='('||*s=='{'||*s=='[') { stack[++top] = *s; } else{ if(top==-1) return false; else { char t = stack[top]; if(*s==')'&&t=='('||*s=='}'&&t=='{'||*s==']'&&t=='[') stack[top--] = '\0'; else return false; } } s++; } if(top==-1) return true; else return false;; }