Skip to content

Instantly share code, notes, and snippets.

@spreered
Created September 13, 2017 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spreered/4b5dc0114040cfe10109b1fc8ebe72a1 to your computer and use it in GitHub Desktop.
Save spreered/4b5dc0114040cfe10109b1fc8ebe72a1 to your computer and use it in GitHub Desktop.
def search_insert(nums, target)
pre= nums[0]
pos = 0
if pre >= target
return 0
else
(1...nums.length).each do |i|
if(nums[i] >= target)
return i
end
pos = i
end
pos = nums.length
return pos
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment