Skip to content

Commit

Permalink
Merge pull request sashaaero#15 from aki1221/leet_942_rb_file
Browse files Browse the repository at this point in the history
leet_942_rb_file
  • Loading branch information
sashaaero committed Oct 10, 2019
2 parents 2d5b480 + c42b6b4 commit 98be689
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions leet_942.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# https://leetcode.com/problems/DI String Match/
# Runtime: 160 ms, faster than 70.83% of Python3 online submissions for DI String Match
def di_string_match(s)
l = s.length-1
lo=0
hi=l+1
ans=[]
(0..l).each do |i|
if s[i].eql?('I')
ans[i]=lo
lo+=1
else
ans[i]=hi
hi-=1
end
end
ans[l+1]=lo
return ans
end

0 comments on commit 98be689

Please sign in to comment.