aboutsummaryrefslogtreecommitdiff
path: root/leetcode/lc-2-add-two-numbers.rkt
diff options
context:
space:
mode:
Diffstat (limited to 'leetcode/lc-2-add-two-numbers.rkt')
-rw-r--r--leetcode/lc-2-add-two-numbers.rkt35
1 files changed, 0 insertions, 35 deletions
diff --git a/leetcode/lc-2-add-two-numbers.rkt b/leetcode/lc-2-add-two-numbers.rkt
deleted file mode 100644
index 8062817..0000000
--- a/leetcode/lc-2-add-two-numbers.rkt
+++ /dev/null
@@ -1,35 +0,0 @@
-#lang racket
-; Definition for singly-linked list:
-
-
-; val : integer?
-; next : (or/c list-node? #f)
-(struct list-node
- (val next) #:mutable #:transparent)
-
-; constructor
-(define (make-list-node val [next-node #f])
- (list-node val next-node))
-
-
-(define/contract (add-two-numbers l1 l2)
- (-> (or/c list-node? #f) (or/c list-node? #f) (or/c list-node? #f))
- (define (process-list node [acc '()])
- (if (list-node-next node)
- (process-list (list-node-next node) (cons (list-node-val node) acc))
- (cons (list-node-val node) acc)))
- (define sum-of-lists (+ (string->number (apply ~a (process-list l1)))
- (string->number (apply ~a (process-list l2)))))
- (define sum-list-digits
- (reverse
- (map (λ (x) (string->number (string x)))
- (string->list (number->string sum-of-lists)))))
- (define (build-list l)
- (if (empty? l)
- #f
- (make-list-node (car l) (build-list (cdr l)))))
- (build-list sum-list-digits))
-
-(define list1 (make-list-node 2 (make-list-node 4 (make-list-node 3))))
-(define list2 (make-list-node 5 (make-list-node 6 (make-list-node 4))))
-(add-two-numbers list1 list2) \ No newline at end of file