寻找空洞

来源:互联网 发布:剑三喵萝捏脸数据下载 编辑:程序博客网 时间:2024/04/28 12:49

这里写图片描述这里写图片描述

public static void searchHollow(String[][] array, int row, int line) {        SparseArray<String> sparseArray = new SparseArray<String>();        for (int i = 1; i < row - 1; i++) {            for (int j = 1; j < line - 1; j++) {                if (Integer.parseInt(array[i][j]) > Integer.parseInt(array[i][j-1])                         && Integer.parseInt(array[i][j]) > Integer.parseInt(array[i][j+1])                        && Integer.parseInt(array[i][j]) > Integer.parseInt(array[i-1][j])                        && Integer.parseInt(array[i][j]) > Integer.parseInt(array[i+1][j])) {                    sparseArray.put((i+1)*j + j, array[i][j]);                }            }        }        for (int i = 0; i < row; i++) {            for (int j = 0; j < line; j++) {                if (sparseArray.get((i+1)*j + j) != null) {                    array[i][j] = "x";                }                System.out.print(array[i][j]);            }            System.out.println();        }

使用稀疏数组可以减少存储空间

0 0
原创粉丝点击