Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Example {
  4.     public static void main(String[] args) {
  5.        
  6.     }
  7.    
  8.     public static int BiggestSubIm(int[][] array) {
  9.         // First we construct every possible sub arrays starting
  10.         // from the upper left corner
  11.        
  12.         //Beforehand you can either create an arraylist of arrays
  13.         // or an array of array ...Duh
  14.        
  15.         //If you really want to use a normal array, you can specify its dimensions
  16.         //Observe that its length is ALWAYS i - 1 (or j - 1 for that matter)
  17.         //So you'll end with an array containing arrays of different dimensions
  18.         // and in that case you use one for loop to track each array (in that array)
  19.         // and another nested for loop that just counts the number of iterations until
  20.         // the end of the row (these iterations are your length)
  21.         // Or even better you can just call .length and retrieve the length
  22.         //of each line xD
  23.         int biggestDim = -1;
  24.         ArrayList<int[][]> subArrays = new ArrayList<int[][]>();
  25.         int i = 0;
  26.         int j = 0;
  27.         while(i < array.length && j < array.length) {
  28.             subArrays.add(getSubArray(array, i+1, j+1));
  29.         }
  30.        
  31.         // Now we just loop through this arrayList list and get the highest one
  32.         for(int k = 0; k < subArrays.size(); k++) {
  33.             if(subArrays.get(k).length >= biggestDim) {
  34.                 biggestDim = subArrays.get(k).length;
  35.             }
  36.         }
  37.        
  38.         return biggestDim;
  39.        
  40.     }
  41.     //To do so and in order to simplify the code I'm gonna use an external
  42.     //method to create my subarrays
  43.    
  44.     public static int[][] getSubArray(int[][] array, int row , int col){
  45.         // I let you find the correct implementation :)
  46.                
  47.                    
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement