fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. char* isBalanced(char* s) {
  5. int len = strlen(s);
  6. char stack[10];
  7. int top = -1;
  8.  
  9. for (int i = 0; i < len / 2; i++) {
  10. if (s[i] == '(' || s[i] == '[' || s[i] == '{') {
  11. stack[++top] = s[i];
  12. }
  13.  
  14. }
  15.  
  16. for (int i = len - 1; i > len / 2; i--) {
  17. char c = stack[top --];
  18. if ((s[i] == ')' && c == '(') ||
  19. (s[i] == ']' && c == '[') ||
  20. (s[i] == '}' && c == '{')) {
  21.  
  22. } else {
  23. return "NO";
  24. }
  25.  
  26. }
  27.  
  28. return "YES";
  29.  
  30. }
  31.  
  32. int main()
  33. {
  34. printf("Hello World\n");
  35.  
  36. char *s = "{[()]}";
  37.  
  38. isBalanced(s);
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 5284KB
stdin
45
stdout
Hello World