make leet-code into a test case
This commit is contained in:
@@ -1,20 +1,14 @@
|
||||
(defun :Void main []
|
||||
(defun :Array<Int> twosum [:Array<Int> numbers target]
|
||||
// solution to: https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/
|
||||
(function :Array<Int> twosum [:Array<Int> numbers target]
|
||||
(let [di (new Map<Int,Int>)]
|
||||
(doFor [i num] (zip (collect (range numbers.length)) numbers Throw)
|
||||
(print "$i $num" )
|
||||
(if (di.exists (- target num))
|
||||
(return [( + 1 (dictGet di (- target num) )) ( + i 1)])
|
||||
)
|
||||
(dictSet di num i)
|
||||
)
|
||||
|
||||
|
||||
)
|
||||
(return null)
|
||||
|
||||
)
|
||||
|
||||
(print (twosum [1 2 3 4 5 6 ] 5) )
|
||||
)
|
||||
(doFor [i num] (enumerate numbers)
|
||||
// (print "$i $num")
|
||||
(if (di.exists (- target num))
|
||||
(return [(+ 1 (dictGet di (- target num))) (+ i 1)]))
|
||||
(dictSet di num i)))
|
||||
(return null))
|
||||
|
||||
(assert (= (.toString [2 3]) (.toString (twosum [1 2 3 4 5 6] 5))))
|
||||
(assert (= (.toString [1 2]) (.toString (twosum [2 7 11 15] 9))))
|
||||
(assert (= (.toString [1 3]) (.toString (twosum [2 3 4] 6))))
|
||||
(assert (= (.toString [1 2]) (.toString (twosum [-1 0] -1))))
|
||||
|
Reference in New Issue
Block a user