Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "regexp"
- )
- func matchParanthesis(expr []byte) bool {
- re := regexp.MustCompile("\\(|\\)")
- yetToMatch := 0
- for _, indexes := range re.FindAllStringIndex(string(expr), -1) {
- switch expr[indexes[0]] {
- case '(':
- yetToMatch += 1
- case ')':
- yetToMatch -= 1
- if yetToMatch < 0 {
- return false
- }
- }
- }
- return yetToMatch == 0
- }
- func main() {
- expr := []byte(`(sasa)sasasa(SS)sssss(sss(s))sssssasackjabiec()sasa((sa)s)sss))`)
- fmt.Println("Hello, playground", matchParanthesis(expr))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement