A well formed java string -
a friend had interview question asking following:
given string comprising of characters (,),{,},[,], determine if formed or not.
in mind have answered no string , "/" character required print said characters. correct or way off base?
if well-formed means each brace closed matching brace , there no incidents ({)}, suggest use stack
- go through each character in string
- if opening brace, push on stack
- if closing brace, pop stack , look, if match -> if go through chars in string , stack empty, string formed
Comments
Post a Comment