Update code.

This commit is contained in:
Calvin Rose
2018-03-14 21:46:56 -04:00
parent 8ec29d9326
commit 5f0bd1e082
3 changed files with 50 additions and 15 deletions
+14
View File
@@ -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)