1. 程式人生 > 其它 >判斷字串是不是迴文串-py&js

判斷字串是不是迴文串-py&js

技術標籤:令人心動的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));