mirror of
https://github.com/janet-lang/janet
synced 2026-09-21 00:28:47 +00:00
Update code.
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
(defn sum3
|
||||
"Solve the 3SUM problem O(n^2) time."
|
||||
[s]
|
||||
(def tab @{})
|
||||
(def solutions [])
|
||||
(def len (length s))
|
||||
(for [k 0 len]
|
||||
(put tab (get s k) k))
|
||||
(for [i 0 len]
|
||||
(for [j 0 len]
|
||||
(def k (get tab (- 0 (get s i) (get s j))))
|
||||
(when (and k (not= k i) (not= k j) (not= i j))
|
||||
(array-push solutions [i j k]))))
|
||||
solutions)
|
||||
Reference in New Issue
Block a user