Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5113f45

Browse files
authored
Create 125__验证回文串__easy.js
1 parent055ad17 commit5113f45

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
*
3+
*
4+
如果在将所有大写字符转换为小写字符、并移除所有非字母数字字符之后,短语正着读和反着读都一样。则可以认为该短语是一个 回文串 。
5+
6+
字母和数字都属于字母数字字符。
7+
8+
给你一个字符串 s,如果它是 回文串 ,返回 true ;否则,返回 false 。
9+
10+
11+
12+
示例 1:
13+
14+
输入: s = "A man, a plan, a canal: Panama"
15+
输出:true
16+
解释:"amanaplanacanalpanama" 是回文串。
17+
示例 2:
18+
19+
输入:s = "race a car"
20+
输出:false
21+
解释:"raceacar" 不是回文串。
22+
示例 3:
23+
24+
输入:s = " "
25+
输出:true
26+
解释:在移除非字母数字字符之后,s 是一个空字符串 "" 。
27+
由于空字符串正着反着读都一样,所以是回文串。
28+
29+
30+
/**
31+
*@param {string} s
32+
*@return {boolean}
33+
*/
34+
varisPalindrome=function(s){
35+
// 替换掉所有非字母和数字以及空格
36+
s=s.replace(/[^a-zA-Z0-9]/g,"").toLowerCase();
37+
returns===[...s].reverse().join("")
38+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp