Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
35 lines (31 loc) · 900 Bytes

File metadata and controls

35 lines (31 loc) · 900 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package leetcode;
import java.util.*;
public class leetcode719 {
/*
* 超出空间限制
* */
ArrayList<Integer> list=new ArrayList<>();
LinkedList<Integer> num=new LinkedList<>();
public int smallestDistancePair(int[] nums, int k) {
//if (nums.length==0||k<=0) return 0;
helper(nums,0,nums.length-1,2);
Collections.sort(list);
return list.get(k-1).intValue();
}
public void helper(int [] nums,int start,int end,int n){
if (n==0){
list.add(Math.abs(num.get(0)-num.get(1)));
return;
}
for (int i = start; i <=end; i++) {
num.addLast(nums[i]);
helper(nums,i+1,end,n-1);
num.removeLast();
}
}
public static void main(String[] args) {
new leetcode719().smallestDistancePair(new int[]{
1,3,1
},1);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.