Skip to content

Commit 6f2cd7b

Browse files
committed
enhanced validPalindrome()
1 parent 72be019 commit 6f2cd7b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/main.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { searchDBG } from "./array/search-in-rotated-sorted-array";
22
import { flatDBG } from "./js_core/flatten";
33
import { findAnagramsDBG } from "./string/find-anagrams";
4+
import { testValidPalindrome } from "./string/valid-palindrome";
45

5-
flatDBG()
6+
testValidPalindrome()

src/string/valid-palindrome.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function validPalindrome(s: string): boolean {
22

3-
const isPalindrome = (str: string, left: number, right: number): boolean => {
3+
const isPalindrome = (left: number, right: number): boolean => {
44
while (left < right) {
5-
if (str[left] !== str[right]) {
5+
if (s[left] !== s[right]) {
66
return false;
77
}
88
left++;
@@ -17,7 +17,7 @@ function validPalindrome(s: string): boolean {
1717
while (left < right) {
1818
if (s[left] !== s[right]) {
1919
// Пробуем удалить один символ с одной из сторон
20-
return isPalindrome(s, left + 1, right) || isPalindrome(s, left, right - 1);
20+
return isPalindrome(left + 1, right) || isPalindrome(left, right - 1);
2121
}
2222
left++;
2323
right--;
@@ -26,7 +26,7 @@ function validPalindrome(s: string): boolean {
2626
return true;
2727
}
2828

29-
function testValidPalindrome(){
29+
export function testValidPalindrome(){
3030
const tests = [
3131
{
3232
input: "abca",

0 commit comments

Comments
 (0)