aboutsummaryrefslogtreecommitdiff
path: root/leetcode/1-two-sum/solution.rkt
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/1-two-sum/solution.rkt
parente191b610c11326b587cf0b01fd6fc37b8d07bb19 (diff)
reorg code
Diffstat (limited to 'leetcode/1-two-sum/solution.rkt')
-rw-r--r--leetcode/1-two-sum/solution.rkt16
1 files changed, 0 insertions, 16 deletions
diff --git a/leetcode/1-two-sum/solution.rkt b/leetcode/1-two-sum/solution.rkt
deleted file mode 100644
index e155160..0000000
--- a/leetcode/1-two-sum/solution.rkt
+++ /dev/null
@@ -1,16 +0,0 @@
-#lang racket
-
-;; https://leetcode.com/problems/two-sum/description/
-
-(define/contract (two-sum nums target)
- (-> (listof exact-integer?) exact-integer? (listof exact-integer?))
- (define h (make-hash))
- (define (loop nums index)
- (define n (car nums))
- (define diff (- target n))
- (if (hash-has-key? h diff)
- (list index (hash-ref h diff))
- (let ()
- (hash-set! h n index)
- (loop (cdr nums) (+ 1 index)))))
- (loop nums 0))