We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
char* isBalanced(char* s) {
char new_str[1001]; int top = -1;
int len = strlen(s), flag = 0;
for (int i = 0; i < len; i++){
top++;
new_str[top] = s[i];
if (top >= 1 && is_a_pair(new_str[top-1], new_str[top])){
top -= 2;
}
if (top == -1 && i == len-1) flag = 1;
}
char res = malloc(4 sizeof(char));
if (flag) strcpy(res, "YES");
else strcpy(res, "NO");
return res;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
char* isBalanced(char* s) { char new_str[1001]; int top = -1; int len = strlen(s), flag = 0; for (int i = 0; i < len; i++){ top++; new_str[top] = s[i]; if (top >= 1 && is_a_pair(new_str[top-1], new_str[top])){ top -= 2; } if (top == -1 && i == len-1) flag = 1; } char res = malloc(4 sizeof(char)); if (flag) strcpy(res, "YES"); else strcpy(res, "NO"); return res; }