Is there any way to make it better in python?

  • 0
    class Solution(object):
        def isStrobogrammatic(self, num):
            dic = {'1':'1','8':'8','6':'9','9':'6','0':'0'}
            for i in range(len(num)):
                if num[i] in dic and dic[num[i]] == num[::-1][i]:
                    return False
            return True

  • 0


    If anyone can correct me if I'm wrong, but does num[::-1] create a new list in reverse each time in the for loop? If that is the case, shouldn't we just match characters with two pointers instead?

  • 0

    I think its better to use num[len(num)-1-i] instead. Its more readable.

Log in to reply

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