判斷字串是不是迴文串-py&js
阿新 • • 發佈:2021-01-20
技術標籤:令人心動的offercode
Python
def isPalindrome(s):
s1 = s[::-1]
if s == s1:
return True
else:
return False
print(isPalindrome('asdfdsa'))
js
function isPalindrome(s){
var left = 0;
var right = s.length-1;
while(left<right){
if(s[left]!=s[right]){
return false;
}
left++;
right--;
}
return true;
}
var str = "asdfdsa";
console.log(isPalindrome(str));