aboutsummaryrefslogtreecommitdiff
path: root/racket/leetcode/lc-844-backspace-string-compare.rkt
blob: a07ec3ce3cce73b1bb6f5a64c255c4eeae52c425 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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)))