public int fillMatrix(int[][] matrix, int min, int max, int cur) {
		if(min == max) {
			matrix[min][min] = cur++;
			return cur;
		}
		int i = min, j = min;
		matrix[i][j] = cur++;
		for(int k = 0; k < 4; ) {
			i += Xs[k];
			j += Ys[k];
			if(i == min && j == min) break; // need to check before assign
			matrix[i][j] = cur++;
			if((i == min || i == max) && (j == min || j == max)) k++;
		}
		return cur;
	}