aboutsummaryrefslogtreecommitdiff
path: root/racket/leetcode/lc-844-backspace-string-compare.rkt
diff options
context:
space:
mode:
Diffstat (limited to 'racket/leetcode/lc-844-backspace-string-compare.rkt')
-rw-r--r--racket/leetcode/lc-844-backspace-string-compare.rkt17
1 files changed, 17 insertions, 0 deletions
diff --git a/racket/leetcode/lc-844-backspace-string-compare.rkt b/racket/leetcode/lc-844-backspace-string-compare.rkt
new file mode 100644
index 0000000..a07ec3c
--- /dev/null
+++ b/racket/leetcode/lc-844-backspace-string-compare.rkt
@@ -0,0 +1,17 @@
+#lang racket
+
+(define/contract (process-backspace-string strng)
+ (-> string? string?)
+ (apply ~a (for/fold ([str-out '()]
+ #:result (reverse str-out))
+ ([character (in-string strng)])
+ (case character
+ [(#\#) (if (empty? str-out)
+ str-out
+ (cdr str-out))]
+ [else (cons character str-out)]))))
+
+(define/contract (backspace-compare s t)
+ (-> string? string? boolean?)
+ (equal? (process-backspace-string s)
+ (process-backspace-string t))) \ No newline at end of file