Simple clean python code

  • 0
    class Solution(object):
    def isValid(self, s):
        stack = ['0']
        for c in s:
            if c != stack[-1] and abs(ord(c) - ord(stack[-1]))<5:
                pp = stack.pop()
        return stack == ['0']

    This code was accepted as 40ms execution time. But when I change '5' to '3', it becomes 70 ms.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.