Ruby Solution
\n# Code\n\nclass NilClass\n    def >(v) = false\n    def ==(v) = false\n    def +(v) = nil\nend\n\nclass TreeNode\n    def TreeNode.set_kv(k, target)\n        
\n# Code\n```\nclass NilClass\n    def >(v) = false\n    def ==(v) = false\n    def +(v) = nil\nend\n\nclass TreeNode\n    def TreeNode.set_kv(k, target)\n        @@k, @@target = k, target\n    end\n\n    def find(ans, d = nil)\n        if val == @@target then\n            [left, right].compact.each {|n| n.find(ans, 1) }\n            return 1\n        end\n        return d if d > @@k\n        (ans << val; return d - 1) if d == @@k\n        childs = [left, right].compact\n        childs.each_with_index {|n, idx|\n            dd = n.find(ans, d + 1)\n            if d.nil? && !dd.nil? then\n                if dd == @@k then\n                    ans << val\n                elsif dd < @@k && childs.size > 1 then\n                    childs[1-idx].find(ans, dd + 1)\n                end\n                return dd + 1\n            end\n        }\n        nil\n    end\nend\n\ndef distance_k(root, target, k)\n    return [target.val] if k.zero?\n    TreeNode.set_kv(k, target.val)\n    root.find(ans = [])\n    ans\nend\n```
['Ruby']