solved a leetcode
This commit is contained in:
7
projects/leet-code/src/leet_code/Main.hx
Normal file
7
projects/leet-code/src/leet_code/Main.hx
Normal file
@@ -0,0 +1,7 @@
|
||||
package leet_code;
|
||||
|
||||
import kiss.Kiss;
|
||||
import kiss.Prelude;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class Main {}
|
||||
20
projects/leet-code/src/leet_code/Main.kiss
Normal file
20
projects/leet-code/src/leet_code/Main.kiss
Normal file
@@ -0,0 +1,20 @@
|
||||
(defun :Void main []
|
||||
(defun :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) )
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user