Created
November 15, 2014 05:47
-
-
Save jrozner/3fb3198b960fcb2dbb5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
) | |
var input = "(((())))" | |
func main() { | |
if !parseParen() { | |
log.Fatal("input does not match") | |
} | |
fmt.Println("input is valid") | |
} | |
func parseParen() bool { | |
current := input[0] | |
input = input[1:] | |
switch current { | |
case '(': | |
if input[0] == '(' { | |
if !parseParen() { | |
return false | |
} | |
} | |
default: | |
return false | |
} | |
current = input[0] | |
input = input[1:] | |
if current == ')' { | |
return true | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment