# 125 Valid Palindrome

string 本身可以直接抓值,不用再轉 Array, eg. name ="hannah", name[0] = "h" / 基本 Regex 要很熟練

LeetCode

Given a string, determine if it is a palindrome, 
considering only alphanumeric characters and ignoring cases.

Note: For the purpose of this problem, we define empty string as valid palindrome.

input: 可以呼略大小寫跟空白
Example 1:

Input: "A man, a plan, a canal: Panama"
Output: true

Example 2:

Input: "race a car"
Output: false

/**
 * @param {string} s
 * @return {boolean}
 */
var isPalindrome = function(s) {}

怎麼解

基本上看到回文題目都跟 Two Pointer 有關,我都習慣 pointer 當頭,ind 當 尾這樣 (不過命名你可以隨便命)。

學到什麼?

  • 真的熟悉題型之後解起來快好多(真有成就感)。這題我本來還先

但其實可以省了 s.split('') 這道,因為字串本身也可以直接就抓

  • Regex: 太久沒用真的會忘記,我會再把它整理到 Tools 類別下面

Last updated

Was this helpful?