Skip to content

Optimizations #1

@midhunpg

Description

@midhunpg

LearnJava/CodingJava/src/main/java/BalancedParanthesis.java

There is no need for the isContinue variable.
Return false whenever you find that the parenthesis is not matching. peek() is not required. can use pop() directly.
The return type of method1() can be changed to boolean. In cases where a closing parenthesis is encountered,

.......................
case '}':
if(!stack.isEmpty()&stack.pop()!='{'){
return false;
}
break;
.....................

return true after the switch block,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions