题目: two-sum
解题:
def two_sum(nums, target)
hash = {}
nums.each_with_index do |num, index|
value = target - num
return hash[value], index if hash[value]
hash[num] = index
end
end
题目: Remove Duplicates from Sorted Array
解题:
def remove_duplicates(nums)
i = 0
for j in 0..nums.length do
if nums[i] != nums[j]
i = i+1
nums[i] = nums[j]
end
end
return i
end