We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticbooleanisBalanced(Stringexpression){// Must be evenif((expression.length()&1)==1)returnfalse;else{char[]brackets=expression.toCharArray();Stack<Character>s=newStack<>();for(charbracket:brackets)switch(bracket){case'{':s.push('}');break;case'(':s.push(')');break;case'[':s.push(']');break;default:if(s.empty()||bracket!=s.peek())returnfalse;s.pop();}returns.empty();}}
Good continuation.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Stacks: Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
Very cool solution, here is with java:
Good continuation.