We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The golang solution using byte to validate the parenthesis hits 0ms compared to ~108ms in javascript. Maybe we shall try to find a better solution.
func isValid(s string) bool { if len(s)%2 != 0 { return false } left := map[byte]struct{}{ '(': struct{}{}, '[': struct{}{}, '{': struct{}{}, } right := map[byte]struct{}{ ')': struct{}{}, ']': struct{}{}, '}': struct{}{}, } bytes := []byte(s) stack := []byte{} for i := range bytes { if _, ok := left[bytes[i]]; ok { stack = append(stack, bytes[i]) } else if _, ok = right[bytes[i]]; ok { if len(stack) == 0 { return false } switch stack[len(stack)-1] { case '(': if bytes[i] != ')' { return false } case '[': if bytes[i] != ']' { return false } case '{': if bytes[i] != '}' { return false } } stack = stack[:len(stack)-1] } else { return false } } if len(stack) == 0 { return true } return false }
The text was updated successfully, but these errors were encountered:
if golang is quicker than JavaScript, it's okay if having an better solution using JavaScript, PRs welcomed!
Sorry, something went wrong.
No branches or pull requests
The golang solution using byte to validate the parenthesis hits 0ms compared to ~108ms in javascript.
Maybe we shall try to find a better solution.
The text was updated successfully, but these errors were encountered: