File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 48
48
819|[ Most Common Word] ( ./0819-most-common-word.js ) |Easy|
49
49
824|[ Goat Latin] ( ./0824-goat-latin.js ) |Easy|
50
50
831|[ Masking Personal Information] ( ./0831-masking-personal-information.js ) |Medium|
51
+ 844|[ Backspace String Compare] ( ./0844-backspace-string-compare.js ) |Easy|
51
52
867|[ Transpose Matrix] ( ./0867-transpose-matrix.js ) |Easy|
52
53
890|[ Find and Replace Pattern] ( ./0890-find-and-replace-pattern.js ) |Medium|
53
54
916|[ Word Subsets] ( ./0916-word-subsets.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 844. Backspace String Compare
3
+ * https://leetcode.com/problems/backspace-string-compare/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given two strings `s` and `t`, return true if they are equal when both
7
+ * are typed into empty text editors. '#' means a backspace character.
8
+ *
9
+ * Note that after backspacing an empty text, the text will continue empty.
10
+ */
11
+
12
+ /**
13
+ * @param {string } s
14
+ * @param {string } t
15
+ * @return {boolean }
16
+ */
17
+ var backspaceCompare = function ( s , t ) {
18
+ return handleBackspaces ( s ) === handleBackspaces ( t ) ;
19
+ } ;
20
+
21
+ function handleBackspaces ( input ) {
22
+ return input . split ( '' ) . reduce ( ( result , char ) => {
23
+ if ( char === '#' ) {
24
+ result . pop ( ) ;
25
+ } else {
26
+ result . push ( char ) ;
27
+ }
28
+ return result ;
29
+ } , [ ] ) . join ( '' ) ;
30
+ }
You can’t perform that action at this time.
0 commit comments