Skip to content

Latest commit

 

History

History
34 lines (27 loc) · 657 Bytes

李戈-20180707.md

File metadata and controls

34 lines (27 loc) · 657 Bytes

LeetCode

题目: 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