Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "regexp"
  6. )
  7.  
  8. func matchParanthesis(expr []byte) bool {
  9. re := regexp.MustCompile("\\(|\\)")
  10. yetToMatch := 0
  11. for _, indexes := range re.FindAllStringIndex(string(expr), -1) {
  12. switch expr[indexes[0]] {
  13. case '(':
  14. yetToMatch += 1
  15. case ')':
  16. yetToMatch -= 1
  17.  
  18. if yetToMatch < 0 {
  19. return false
  20. }
  21. }
  22.  
  23. }
  24. return yetToMatch == 0
  25.  
  26. }
  27. func main() {
  28. expr := []byte(`(sasa)sasasa(SS)sssss(sss(s))sssssasackjabiec()sasa((sa)s)sss))`)
  29. fmt.Println("Hello, playground", matchParanthesis(expr))
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement