Skip to content

update BalancedBrackets #1029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2019
Merged

update BalancedBrackets #1029

merged 1 commit into from
Oct 13, 2019

Conversation

realDuYuanChao
Copy link
Member

@realDuYuanChao realDuYuanChao commented Oct 12, 2019

code reuse!

case ')':
case ']':
case '}':
    if (!(!bracketsStack.isEmpty() && isPaired(bracketsStack.pop(), bracket))) {
         return false;
    }

@realDuYuanChao
Copy link
Member Author

@yanglbme Please review ^_^

* @return {@code true} if {@code leftBracket} and {@code rightBrackets} is paired,
* otherwise {@code false}
*/
public static boolean isPaired(char leftBracket, char rightBrackets) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be rightBracket, not rightBrackets:

/**
 * Check if {@code leftBracket} and {@code rightBracket} is paired or not
 *
 * @param leftBracket   left bracket
 * @param rightBracket right bracket
 * @return {@code true} if {@code leftBracket} and {@code rightBracket} is paired,
 * otherwise {@code false}
 */
public static boolean isPaired(char leftBracket, char rightBracket) {
    char[][] pairedBrackets = {
            {'(', ')'},
            {'[', ']'},
            {'{', '}'},
            {'<', '>'}
    };
    for (char[] pairedBracket : pairedBrackets) {
        if (pairedBracket[0] == leftBracket && pairedBracket[1] == rightBracket) {
            return true;
        }
    }
    return false;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated! Please review again! @yanglbme

*/
class BalancedBrackets {

/**
* Check if {@code leftBracket} and {@code rightBrackets} is paired or not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Check if {@code leftBracket} and {@code rightBrackets} is paired or not
* Check if {@code leftBracket} and {@code rightBracket} is paired or not

* Check if {@code leftBracket} and {@code rightBrackets} is paired or not
*
* @param leftBracket left bracket
* @param rightBrackets right bracket
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param rightBrackets right bracket
* @param rightBracket right bracket

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review again! Thanks

@yanglbme yanglbme merged commit eec7f3e into TheAlgorithms:master Oct 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants