Hallo,

ich weiß, ich bin nicht so gut. Allerdings verstehe ich nicht, wie das richtig gehen würde. Was mache ich falsch?

Bitte ohne alles zu ändern, sprich Stack und Co.

public class Solution {
  public bool IsValid(string s) {
    if (s.Length % 2 != 0) {
      return false;
    }

    char[] marks = new char[] { '(', ')', '[', ']', '{', '}' };

    for (int i = 0; i < s.Length / 2; i++) {
      for (int j = 0; j < marks.Length; j++) {
        if (s[i] == marks[j] && s[s.Length - 1 - i] != marks[j + 1]) {
          return false;
        }
      }
    }

    return true;
  }
}

Es geht um einen Algorithmus, der schaut, ob Klammern richtig gesetzt worden sind:

()[) -> false,
()[]([]) -> true