• + 0 comments
    input = input.replaceAll("\\(\\)|\\[\\]|\\{\\}", ""))
    

    This will replace ()[]{} with "" , making input length lesser than earlier

    Now this *input.length()* will be the length of ()[]{} removed input

    So, if you start with ([{}])...

    input.length() is 6 , after input.replaceAll(..), *input* will be '([])' , and its length is 4 where *6!=4*,so while loop continues

    1. '([{}])' != '([])' <-- result of first replaceAll
    2. '([])' != '()' <-- result of second
    3. '()' != '' <-- result of third
    4. '' == ''
    5. and isEmpty() returns true