【发布时间】:2016-01-09 01:11:51
【问题描述】:
我试图解决在nums[i]+nums[j]==target的列表中找到两个数字索引:
(defn two-sum [nums target]
"Find sum of two numbers equals to target"
(if (<= 1 (count nums))
nil)
(let [hdict (hash-map)]
(for [i (range 1 (count nums))]
(if (get hdict (nums i))
[(get hdict (nums i)) i] ;return hdict[nums[i]] and i
(assoc hdcit (- target (nums i)) i)))))
我收到了这个错误:
1. Caused by java.lang.RuntimeException
Unable to resolve symbol: hdcit in this context
我很困惑:我已经将hdict绑定为hash-map,为什么仍然无法解决?
【问题讨论】:
-
您在最后一行转换了
i和c。不过,还有一些其他问题值得解释
标签: clojure