Created
July 5, 2019 08:44
-
-
Save manojnaidu619/a970dcf124b6a3583c32bd82dcf1354a to your computer and use it in GitHub Desktop.
Leetcode Solution for "Transpose Matrix" problem in Ruby
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 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