Why this solution is not o(n)

class Solution:
    # @param A : string
    # @return an integer
    def solve(self, A):
        for i in range(len(A)):
            if A==A[::-1]:
                return 1
            else: A=B
        return 0


It costs O(n) just to build a substring and to compare it with it’s reverse. Together with the O(n) outer loop you get O(n²).


@ wing-chung-leung it helped, :slight_smile: