aboutsummaryrefslogtreecommitdiff
path: root/leetcode/20-valid-parentheses
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2024-02-25 20:11:54 +0800
committerMistivia <i@mistivia.com>2024-02-25 20:11:54 +0800
commit515ecbf5a20a8e432a998b0a543bedcb1bd64cf4 (patch)
tree6353c603a8cf0276553f420205f8d1c730a318ce /leetcode/20-valid-parentheses
parente191b610c11326b587cf0b01fd6fc37b8d07bb19 (diff)
reorg code
Diffstat (limited to 'leetcode/20-valid-parentheses')
-rw-r--r--leetcode/20-valid-parentheses/solution.rkt33
1 files changed, 0 insertions, 33 deletions
diff --git a/leetcode/20-valid-parentheses/solution.rkt b/leetcode/20-valid-parentheses/solution.rkt
deleted file mode 100644
index 559b90c..0000000
--- a/leetcode/20-valid-parentheses/solution.rkt
+++ /dev/null
@@ -1,33 +0,0 @@
-#lang racket
-
-;; https://leetcode.com/problems/valid-parentheses/
-
-(define (is-left-paren c)
- (or (eq? c #\u28)
- (eq? c #\[)
- (eq? c #\{)))
-
-(define (right-paren c)
- (cond ((eq? c #\u28) #\u29)
- ((eq? c #\[) #\])
- ((eq? c #\{) #\})))
-
-(define/contract (is-valid s)
- (-> string? boolean?)
- (define (loop s stack)
- (if (= 0 (string-length s))
- (null? stack)
- (let ()
- (define c (string-ref s 0))
- (define remain (substring s 1))
- (if (is-left-paren c)
- (loop remain (cons c stack))
- (if (null? stack)
- #f
- (let ()
- (define stack-top (car stack))
- (if (eq? c (right-paren stack-top))
- (loop remain (cdr stack))
- #f)))))))
- (loop s '()))
-