brewersfan1976

rows_rearranging.rb

Aug 15th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.59 KB | None | 0 0
  1. def rowsRearranging(matrix)
  2.     sorted_array = Array.new
  3.     sorted_array = matrix.sort
  4.     x_length = matrix.length
  5.     y_length = matrix[0].length
  6.     x = 0
  7.     y = 0
  8.    
  9.     if x_length == 1 or y_length == 1 then
  10.        return true
  11.     end
  12.        
  13.     while (y < y_length)
  14.           while (x < x_length - 1)
  15.                 if sorted_array[x + 1][y] <= sorted_array[x][y] then
  16.                    return false
  17.                 end
  18.              
  19.                 x = x + 1
  20.           end
  21.              
  22.           x = 0
  23.           y = y + 1
  24.     end
  25.        
  26.     return true
  27.    
  28. end
Advertisement
Add Comment
Please, Sign In to add comment