# Simple Java Solution

• 网上查的移位法

``````import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution {

public void add(int[] array, int[] nums, List<List<Integer>> result) {
List<Integer> list = new ArrayList<>();
for (int j = 0; j < array.length; j++) {
if (array[j] == 1) {
}
}
}

public List<List<Integer>> combine(int n, int k) {
List<List<Integer>> result = new ArrayList<>();
if (n < k) {
return result;
}

int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = i + 1;
}

int[] array = new int[n];
Arrays.fill(array, 0, k, 1);

boolean hasMore = true;
while (hasMore) {
hasMore = false;
for (int i = 0; i < n - 1; i++) {
if (array[i] == 1 && array[i + 1] == 0) {
hasMore = true;
array[i] = 0;
array[i + 1] = 1;

if (array[0] == 0) {
for (int j = 0, m = 0; m < i; m++) {
if (array[m] == 1) {
array[j++] = 1;
array[m] = 0;
}
}
}

break;
}
}
}
return result;
}

public static void main(String[] args) {
List<List<Integer>> result = new Solution().combine(4, 2);
System.out.println(result);
}
}
``````

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.