循环时有效回文

时间:2019-03-15 05:34:44

标签: string while-loop palindrome

第一版

class Solution(object):
    def isPalindrome(self, s):
        f,l = 0,len(s)-1
        while f<l:
            while **f<l** and not s[f].isalnum():
                f+=1
            while **f<l** and not s[l].isalnum():
                l-=1
            if s[f].lower()!=s[l].lower():
                return False
            f+=1 
            l-=1

        return True

第二版

class Solution(object):
    def isPalindrome(self, s):

        f,l = 0,len(s)-1
        while f<l:
            while not s[f].isalnum():
                f+=1
            while not s[l].isalnum():
                l-=1
            if s[f].lower()!=s[l].lower():
                return False
            f+=1 
            l-=1

        return True

嗨,谁能告诉我为什么在“ while”循环中

非常感谢你们!

0 个答案:

没有答案