leet-code use enumerate with 1-index
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
// solution to: https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/
|
// solution to: https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/
|
||||||
(function :Array<Int> twosum [:Array<Int> numbers target]
|
(function :Array<Int> twosum [:Array<Int> numbers target]
|
||||||
(let [di (new Map<Int,Int>)]
|
(let [di (new Map<Int,Int>)]
|
||||||
(doFor [i num] (enumerate numbers)
|
(doFor [i num] (enumerate numbers 1)
|
||||||
// (print "$i $num")
|
// (print "$i $num")
|
||||||
(if (di.exists (- target num))
|
(if (di.exists (- target num))
|
||||||
(return [(+ 1 (dictGet di (- target num))) (+ i 1)]))
|
(return [(dictGet di (- target num)) i]))
|
||||||
(dictSet di num i)))
|
(dictSet di num i)))
|
||||||
(return null))
|
(return null))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user