Skip to content

Commit 130bd08

Browse files
committed
Add solution #125
1 parent 3390d01 commit 130bd08

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
119|[Pascal's Triangle II](./0119-pascals-triangle-ii.js)|Easy|
8080
120|[Triangle](./0120-triangle.js)|Medium|
8181
121|[Best Time to Buy and Sell Stock](./0121-best-time-to-buy-and-sell-stock.js)|Easy|
82+
125|[Valid Palindrome](./0125-valid-palindrome.js)|Easy|
8283
128|[Longest Consecutive Sequence](./0128-longest-consecutive-sequence.js)|Medium|
8384
133|[Clone Graph](./0133-clone-graph.js)|Medium|
8485
134|[Gas Station](./0134-gas-station.js)|Medium|

solutions/0125-valid-palindrome.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* 125. Valid Palindrome
3+
* https://leetcode.com/problems/valid-palindrome/
4+
* Difficulty: Easy
5+
*
6+
* A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and
7+
* removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric
8+
* characters include letters and numbers.
9+
*
10+
* Given a string s, return true if it is a palindrome, or false otherwise.
11+
*/
12+
13+
/**
14+
* @param {string} s
15+
* @return {boolean}
16+
*/
17+
var isPalindrome = function(s) {
18+
const string = s.replace(/[^A-Z\d]+/ig, '').toLowerCase();
19+
return string.split('').reverse().join('') === string;
20+
};

0 commit comments

Comments
 (0)