TwoSum | Expected: [0, 1], instead got: [0, 0] | Ruby indexs' problem

后端 未结 0 543
伪装坚强ぢ
伪装坚强ぢ 2021-01-30 00:15
def two_sum(nums, tg)
  b = []
  nums.sort.combination(2){|x| b << x}
  c = b.reject{|x| x.sum != tg}[0]
  [nums.index(c[0]), nums.index(c[1])]
end
<
相关标签:
回答
  • 消灭零回复
提交回复
热议问题