CopyPastor

Detecting plagiarism made easy.

Score: 0.8264126181602478; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2019-02-06
by Harsh Manvar

Original Post

Original - Posted on 2017-10-12
by Kavitha Madhavaraj



            
Present in both answers; Present only in the new answer; Present only in the old answer;

openList = ["[","{","("] closeList = ["]","}",")"] def balance(myStr): stack= [] for i in myStr: if i in openList: stack.append(i) elif i in closeList: pos = closeList.index(i) if ((len(stack) > 0) and (openList[pos] == stack[len(stack)-1])): stack.pop() else: return "Unbalanced" if len(stack) == 0: return "Balanced" print balance("{[()](){}}")
My solution here works for brackets, parentheses & braces
openList = ["[","{","("] closeList = ["]","}",")"] def balance(myStr): stack= [] for i in myStr: if i in openList: stack.append(i) elif i in closeList: pos = closeList.index(i) if ((len(stack) > 0) and (openList[pos] == stack[len(stack)-1])): stack.pop() else: return "Unbalanced" if len(stack) == 0: return "Balanced" print balance("{[()](){}}")

        
Present in both answers; Present only in the new answer; Present only in the old answer;