private void update(char[][] grid, int rows, int cols, List<Integer> list) {
	        while (!list.isEmpty()) {
	            List<Integer> nextList = new LinkedList<>();
	            for (Integer e : list) {
	                int r = e / cols;
	                int c = e % cols;
	                for (int[] move : moves) {
	                    int r2 = r + move[0];
	                    int c2 = c + move[1];
	                    if (r2 >= 0 && r2 < rows && c2 >= 0 && c2 < cols && grid[r2][c2] == '1') {
	                        grid[r2][c2] = '0';
	                        nextList.add(cols*r2 + c2);
	                    }
	                }
	            }
	            list = nextList;
	        }
	    }