Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class Example {
- public static void main(String[] args) {
- }
- public static int BiggestSubIm(int[][] array) {
- // First we construct every possible sub arrays starting
- // from the upper left corner
- //Beforehand you can either create an arraylist of arrays
- // or an array of array ...Duh
- //If you really want to use a normal array, you can specify its dimensions
- //Observe that its length is ALWAYS i - 1 (or j - 1 for that matter)
- //So you'll end with an array containing arrays of different dimensions
- // and in that case you use one for loop to track each array (in that array)
- // and another nested for loop that just counts the number of iterations until
- // the end of the row (these iterations are your length)
- // Or even better you can just call .length and retrieve the length
- //of each line xD
- int biggestDim = -1;
- ArrayList<int[][]> subArrays = new ArrayList<int[][]>();
- int i = 0;
- int j = 0;
- while(i < array.length && j < array.length) {
- subArrays.add(getSubArray(array, i+1, j+1));
- }
- // Now we just loop through this arrayList list and get the highest one
- for(int k = 0; k < subArrays.size(); k++) {
- if(subArrays.get(k).length >= biggestDim) {
- biggestDim = subArrays.get(k).length;
- }
- }
- return biggestDim;
- }
- //To do so and in order to simplify the code I'm gonna use an external
- //method to create my subarrays
- public static int[][] getSubArray(int[][] array, int row , int col){
- // I let you find the correct implementation :)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement