Skip to content

Commit

Permalink
Merge pull request #3 from aki1221/GH-1
Browse files Browse the repository at this point in the history
leet code 941 solution
  • Loading branch information
sashaaero authored Oct 10, 2019
2 parents 872b764 + 7e4a3e4 commit 55f91b7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions leet_941.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# https://leetcode.com/problems/valid-mountain-array/
# Runtime: 52 ms, faster than 73.08% of ruby online submissions for valid-mountain-array.

def valid_mountain_array(a)
l = a.length
if l < 3
return false
else
l=l
i=0
while(i+1<l && a[i] < a[i+1])
i+=1
end
if i.eql?(0) || i.eql?(l-1)
return false
end
while(i+1<l && a[i+1] < a[i])
i+=1
end
end
return i.eql?(l-1)
end

0 comments on commit 55f91b7

Please sign in to comment.