This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @param {Integer[]} height | |
# @return {Integer} | |
def max_area(heights) | |
max = 0 | |
heights.each_with_index do |y, x| | |
heights.each_with_index do |y1, x1| | |
width = (x - x1).abs | |
area = [y, y1].min * width | |
max = area if area >= max | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @param {Integer[]} prices | |
# @return {Integer} | |
def max_profit(prices) | |
mp = 0 | |
prices.each_with_index do |price, i| | |
for n in (i + 1)..prices.count do | |
profit = prices[n].to_i - price | |
mp = profit if profit > mp | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @param {String[]} words | |
# @param {String} order | |
# @return {Boolean} | |
def is_alien_sorted(words, order) | |
sorted = words.sort do |a, b| | |
cmp = [a.length, b.length].max.times do |i| | |
next if a[i] === b[i] | |
break i | |
end | |
if cmp >= a.length || cmp >= b.length |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @param {String} s | |
# @return {String} | |
def min_remove_to_make_valid(s) | |
chars = s.split('') | |
op = chars.reduce(0) { |a, c| a + (c == '(' ? 1 : 0) } | |
cl = chars.reduce(0) { |a, c| a + (c == ')' ? 1 : 0) } | |
diff = op - cl | |
chars.select do |c| | |
if diff === 0 | |
true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
## | |
# This is script with usefull tips taken from: | |
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx | |
# | |
# install it: | |
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Blog < Thor | |
no_tasks do | |
def config | |
{ | |
:u => 'username', # user | |
:p => 'password', # pass | |
:h => 'ftp://your.ftpserver.com', # host | |
:r => 'octopress', # remote dir | |
:l => File.basename(File.join(__FILE__, '..', 'public')) # local dir |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def valid? version | |
pattern = /^\d+\.\d+\.\d+(\-(dev|beta|rc\d+))?$/ | |
raise "Tried to set invalid version: #{version}".red unless version =~ pattern | |
end | |
def correct_version version | |
ver, flag = version.split '-' | |
v = ver.split '.' | |
(0..2).each do |n| | |
v[n] = v[n].to_i |