File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Runtime: 17ms, Memory: 63.18MB
3+ *
4+ * Time Complexity: O(n)
5+ * - Array to Set takes O(n)
6+ * - Compare Set size and array length takes O(1)
7+ * Space Complexity: O(n)
8+ * - Space for Set : O(n)
9+ */
10+
11+ /**
12+ * @param {number[] } nums
13+ * @return {boolean }
14+ */
15+ var containsDuplicate = function ( nums ) {
16+ return new Set ( nums ) . size !== nums . length
17+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Runtime: 7ms, Memory: 55.02MB
3+ *
4+ * Time Complexity: O(n)
5+ * Space Complexity: O(n)
6+ */
7+
8+ /**
9+ * @param {string } s
10+ * @return {boolean }
11+ */
12+ function isPalindrome ( s ) {
13+ const alphanumeric = getAlphanumeric ( s )
14+ return alphanumeric === alphanumeric . split ( "" ) . reverse ( ) . join ( "" )
15+ }
16+
17+ function getAlphanumeric ( string ) {
18+ const number = / [ 0 - 9 ] /
19+ const alphabet = / [ a - z A - Z ] /
20+ let alphanumeric = [ ]
21+
22+ for ( const str of string ) {
23+ if ( number . test ( str ) || alphabet . test ( str ) ) {
24+ alphanumeric . push ( str )
25+ }
26+ }
27+ return alphanumeric . join ( "" ) . toLowerCase ( )
28+ }
You can’t perform that action at this time.
0 commit comments