Skip to content

Commit e075aae

Browse files
committed
Sync LeetCode submission Runtime - 65 ms (26.82%), Memory - 18.1 MB (12.73%)
1 parent 1215ac1 commit e075aae

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
# Approach: Two Pointers
22

3-
# Time: O(N)
3+
# Time: O(n)
44
# Space: O(1)
55

66
class Solution:
7+
def check_palindrome(self, s, i, j):
8+
while i < j:
9+
if s[i] != s[j]:
10+
return False
11+
i += 1
12+
j -= 1
13+
return True
14+
715
def validPalindrome(self, s: str) -> bool:
8-
def check_palindrome(s, i, j):
9-
while i < j:
10-
if s[i] != s[j]:
11-
return False
12-
i += 1
13-
j -= 1
14-
return True
15-
16-
i = 0
17-
j = len(s) - 1
16+
i, j = 0, len(s) - 1
17+
1818
while i < j:
1919
if s[i] != s[j]:
20-
return check_palindrome(s, i + 1, j) or check_palindrome(s, i, j - 1)
20+
return self.check_palindrome(s, i, j - 1) or self.check_palindrome(s, i+ 1, j)
2121
i += 1
2222
j -= 1
23-
23+
2424
return True
25-

0 commit comments

Comments
 (0)