ruby - LeetCode 中Combination Sum III 代码在终端编译正确,但是submit时出现报错
PHP中文网
PHP中文网 2017-04-24 09:11:03
0
1
995

代码如下

$f = 0
$tmp = Array.new
$res = Array.new

def combination_sum3(k, n)

if (k > 9) or (k < 1) or (n > 9) or (n < 1)
    return $res
end
f = $f + 1

if (n < (2 * f + k - 1  ) * k / 2) && (k != 1 )
    return $res
end

if k != 1
    for i in f .. n/k do
        $f = i
        $tmp << i
        combination_sum3(k - 1, n - i)
        $tmp.pop
    end
elsif n > $tmp[-1]
    $tmp << n
    $res << $tmp.clone
    $tmp.pop
end

end

但是最后submit时出错

Runtime Error Message: Line 48: in `block in _driver'
小白,初用LeetCode和segmentfault

PHP中文网
PHP中文网

认证0级讲师

Antworte allen(1)
黄舟

可能是 你输入的 input 格式有问题
不要直接复制题目中的输入

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!