File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change
1
+ function backspaceCompare ( s : string , t : string ) : boolean {
2
+ // initialize first and second string array
3
+ let firstString : string [ ] = [ ] ;
4
+ let secondString : string [ ] = [ ] ;
5
+
6
+ // iterate the first string
7
+ for ( let c of s ) {
8
+ c !== "#" ? firstString . push ( c ) : firstString . pop ( ) ;
9
+ }
10
+
11
+ // iterate the second string
12
+ for ( let c of t ) {
13
+ c !== "#" ? secondString . push ( c ) : secondString . pop ( ) ;
14
+ }
15
+
16
+ // check the value of first and second string
17
+ return firstString . join ( "" ) === secondString . join ( "" ) ;
18
+ }
19
+
20
+ console . log ( backspaceCompare ( "ab#c" , "ad#c" ) ) ; // true
21
+ console . log ( backspaceCompare ( "ab##" , "c#d#" ) ) ; // true
22
+ console . log ( backspaceCompare ( "a##c" , "#a#c" ) ) ; // true
23
+ console . log ( backspaceCompare ( "a#c" , "b" ) ) ; //
You can’t perform that action at this time.
0 commit comments