Skip to content

Commit

Permalink
leet_942_rb_file
Browse files Browse the repository at this point in the history
  • Loading branch information
sharawatankit committed Oct 10, 2019
1 parent 872b764 commit c42b6b4
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 c42b6b4

Please sign in to comment.