Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void check(int[][] buildingss) {
- int lastHeight = 0;
- for (int x = 0; x < buildingss.length; x++) {
- for (int y = 0; y < buildingss[x].length; y++) {
- if (lastHeight == 0)
- lastHeight = buildingss[x][y];
- int val = checky(buildingss, x, y, lastHeight);
- if (val != lastHeight && val != 0) {
- lastHeight = val;
- }
- }
- }
- ArrayList end = new ArrayList(mappig.values());
- Collections.sort(end);
- for (int i = 0; i < end.size(); i++) {
- System.out.println(i + " " + end.get(i));
- }
- }
- public static int checky(int[][] buildingss, int x, int y, int lastHeight) {
- int val = buildingss[x][y];
- if (val == 0)
- return 0;
- if (val != lastHeight) {
- count++;
- mappig.putIfAbsent(count, 1);
- } else
- mappig.putIfAbsent(count, 0);
- if (val == lastHeight)
- mappig.put(count, mappig.get(count) + 1);
- buildingss[x][y] = 0;
- if (x > 0)
- if (buildingss[x - 1][y] == val)
- checky(buildingss, x - 1, y, val);
- if (y > 0)
- if (buildingss[x][y - 1] == val)
- checky(buildingss, x, y - 1, val);
- if (x < buildingss.length - 1)
- if (buildingss[x + 1][y] == val)
- checky(buildingss, x + 1, y, val);
- if (y < buildingss.length - 1)
- if (buildingss[x][y + 1] == val)
- checky(buildingss, x, y + 1, val);
- return val;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement