LeetCode 23 in Clojure — imperative PriorityQueue vs. functional priority-map

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

It's becoming a hobby to solve the same problems as you in k. In this case I don't think k even has linked lists or priority queues so it's kinda apples to oranges, but here's the closest I could do (edit: I could do better):
({x[<x]}@, )/ (1 4 5;1 3 4;2 6)
{x[<x]}@ defines and applies a function sorting its input list., joins it's 2 input lists. The parens on the left turn that into 1 function which / then folds through the argument, which is the list of lists of test data defined between the parens on the right.

dukereg
Автор

You Clojure guys are insane... and not in a good way. This is extremely unreadable and difficult to understand. I'm not talking about data structures and algorithms either... I could code this up in 5 mins in Python or Java.

austecon
Автор

Here is a k version that uses roughly the same approach as yours except using k's normal lists:

/Merge pre-sorted lists together efficiently (I hope) by repeatedly sorting by the first elements and moving the least element to the result.
mrg:{( (#*:){[ls;r] s:ls@<*'ls; ( $[1=#*s;1_s;(, 1_*s), 1_s] ; r, **s )}//(x;!0) )[1]}
mrg@(1 4 5;1 3 4; 2 6)
1 1 2 3 4 4 5 6

dukereg
visit shbcf.ru