We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0867cbf commit 4428aecCopy full SHA for 4428aec
算法/验证回文字符串2.js
@@ -0,0 +1,37 @@
1
+/**
2
+ * @param {string} s
3
+ * @return {boolean}
4
+ */
5
+var validPalindrome = function(s) {
6
+ var i = 0;
7
+ var j = s.length - 1
8
+
9
+ // 两个指针往中间缩进
10
+ while (i < j && s[i] === s[j]) {
11
+ i++
12
+ j--
13
+ }
14
15
+ // 遇到相对位置不相等了 判断删除一位后的情况
16
+ if (isPalindrome(i + 1, j)) {
17
+ return true
18
19
+ if (isPalindrome(i, j - 1)) {
20
21
22
23
+ // 工具方法,用于判断字符串是否回文
24
+ function isPalindrome(st, ed) {
25
+ while(st<ed) {
26
+ if(s[st] !== s[ed]) {
27
+ return false
28
29
+ st++
30
+ ed--
31
32
33
34
35
+ // 这样都不满足 那就不符合要求了
36
37
+};
0 commit comments