Saturday, April 23, 2022

[LeetCode] 125. Valid Palindrome

    

"踏上LeetCode解題之路,順手紀錄一下PHP練功的過程囉。這是第十三篇~~"


Valid Palindrome - LeetCode


思考過程

待補上


結果

class Solution {

    /**
     * @param String $s
     * @return Boolean
     */
    function isPalindrome($s) {
        $string = strtolower(preg_replace("/[^a-zA-Z0-9]/", "", $s));
        if($string == strrev($string))
            return true;
        else
            return false;
    }
}

參考資料

PHP strtolower() 函数

PHP preg_replace() 函数

PHP strrev() 函数

/[^a-zA-Z0-9]/ - Google Search

Contact Form

Name

Email *

Message *