Skip to content

Instantly share code, notes, and snippets.

@manojnaidu619
Created July 5, 2019 08:44
Show Gist options
  • Save manojnaidu619/a970dcf124b6a3583c32bd82dcf1354a to your computer and use it in GitHub Desktop.
Save manojnaidu619/a970dcf124b6a3583c32bd82dcf1354a to your computer and use it in GitHub Desktop.
Leetcode Solution for "Transpose Matrix" problem in Ruby
def transpose(a)
return a if a.empty?
sub = a[0].size
b = Array.new
c = Array.new
if a.size == 1
a[0].each do |i|
b << [i]
end
p b
else
for x in 0..a[0].size-1
for y in 0..a.size-1
b << a[y][x]
end
end
until b.empty?
c << b.take(a.size)
a.size.times do
b.delete_at(0)
end
end
p c
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment