Write a function that takes a string s
containing bracket characters: '(', ')', ', ', '[', ']'.
Determine if the string is valid by checking these rules:
The function should return true
for valid bracket strings, and false
for invalid ones.
Constraints:
Examples:
// Example 1: const s1 = "[]"; console.log(isValid(s1)); // Output: true // Example 2: const s2 = "([{}])"; console.log(isValid(s2)); // Output: true // Example 3: const s3 = "[(])"; console.log(isValid(s3)); // Output: false // Explanation: The brackets are not closed in the correct order.