Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 有效回文while循环_String_While Loop_Palindrome - Fatal编程技术网

String 有效回文while循环

String 有效回文while循环,string,while-loop,palindrome,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

第一版

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
类解决方案(对象):
def isPalindrome(自身):
f、 l=0,len(s)-1
而f
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