Skip to content

Commit e17c93f

Browse files
committed
change all file to unix format
1 parent 70b663f commit e17c93f

File tree

322 files changed

+14374
-14374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

322 files changed

+14374
-14374
lines changed

3sum-closest/Solution.java

+35-35
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
public class Solution {
2-
public int threeSumClosest(int[] num, int target) {
3-
4-
if(num.length < 3) return 0;
5-
6-
Arrays.sort(num);
7-
8-
int pneg = 0 , ppos = num.length - 1;
9-
10-
int closest = num[0] + num[1] + num[2];
11-
12-
while(ppos > 0){
13-
while(pneg < ppos){
14-
int sum = num[pneg];
15-
sum += num[ppos];
16-
17-
for(int i = pneg + 1; i < ppos; i++){
18-
if(Math.abs(target - (num[i] + sum)) < Math.abs(target - closest) ){
19-
closest = num[i] + sum;
20-
}
21-
}
22-
23-
int old = num[pneg];
24-
while(pneg < ppos && num[pneg] == old) pneg++;
25-
}
26-
27-
pneg = 0;
28-
29-
int old = num[ppos];
30-
while(ppos > 0 && num[ppos] == old) ppos--;
31-
}
32-
33-
34-
return closest;
35-
}
1+
public class Solution {
2+
public int threeSumClosest(int[] num, int target) {
3+
4+
if(num.length < 3) return 0;
5+
6+
Arrays.sort(num);
7+
8+
int pneg = 0 , ppos = num.length - 1;
9+
10+
int closest = num[0] + num[1] + num[2];
11+
12+
while(ppos > 0){
13+
while(pneg < ppos){
14+
int sum = num[pneg];
15+
sum += num[ppos];
16+
17+
for(int i = pneg + 1; i < ppos; i++){
18+
if(Math.abs(target - (num[i] + sum)) < Math.abs(target - closest) ){
19+
closest = num[i] + sum;
20+
}
21+
}
22+
23+
int old = num[pneg];
24+
while(pneg < ppos && num[pneg] == old) pneg++;
25+
}
26+
27+
pneg = 0;
28+
29+
int old = num[ppos];
30+
while(ppos > 0 && num[ppos] == old) ppos--;
31+
}
32+
33+
34+
return closest;
35+
}
3636
}

3sum/Solution.java

+38-38
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
public class Solution {
2-
public List<List<Integer>> threeSum(int[] num) {
3-
4-
Arrays.sort(num);
5-
6-
ArrayList<List<Integer>> found = new ArrayList<List<Integer>>();
7-
8-
int pneg = 0 , ppos = num.length - 1;
9-
10-
11-
while(ppos > 0 && num[ppos] >= 0){
12-
while(pneg < ppos && num[pneg] <= 0 && num[ppos] >= 0){
13-
int sum = num[pneg];
14-
sum += num[ppos];
15-
16-
for(int i = pneg + 1; i < ppos; i++){
17-
if(num[i] + sum == 0){
18-
found.add(Arrays.asList(new Integer[]{num[pneg], num[i] ,num[ppos]}));
19-
20-
break;
21-
}
22-
}
23-
24-
int old = num[pneg];
25-
while(pneg < ppos && num[pneg] == old) pneg++;
26-
}
27-
28-
pneg = 0;
29-
30-
int old = num[ppos];
31-
while(ppos > 0 && num[ppos] == old) ppos--;
32-
}
33-
34-
35-
return found;
36-
37-
}
38-
}
1+
public class Solution {
2+
public List<List<Integer>> threeSum(int[] num) {
3+
4+
Arrays.sort(num);
5+
6+
ArrayList<List<Integer>> found = new ArrayList<List<Integer>>();
7+
8+
int pneg = 0 , ppos = num.length - 1;
9+
10+
11+
while(ppos > 0 && num[ppos] >= 0){
12+
while(pneg < ppos && num[pneg] <= 0 && num[ppos] >= 0){
13+
int sum = num[pneg];
14+
sum += num[ppos];
15+
16+
for(int i = pneg + 1; i < ppos; i++){
17+
if(num[i] + sum == 0){
18+
found.add(Arrays.asList(new Integer[]{num[pneg], num[i] ,num[ppos]}));
19+
20+
break;
21+
}
22+
}
23+
24+
int old = num[pneg];
25+
while(pneg < ppos && num[pneg] == old) pneg++;
26+
}
27+
28+
pneg = 0;
29+
30+
int old = num[ppos];
31+
while(ppos > 0 && num[ppos] == old) ppos--;
32+
}
33+
34+
35+
return found;
36+
37+
}
38+
}

4sum/Solution.java

+83-83
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,83 @@
1-
public class Solution {
2-
3-
static class TwoSum {
4-
int index1;
5-
int index2;
6-
7-
boolean overlap(TwoSum other){
8-
if(this == other) return true;
9-
10-
if(index1 == other.index1) return true;
11-
if(index2 == other.index1) return true;
12-
13-
if(index1 == other.index2) return true;
14-
if(index2 == other.index2) return true;
15-
16-
return false;
17-
}
18-
}
19-
20-
public List<List<Integer>> fourSum(int[] num, int target) {
21-
ArrayList<List<Integer>> found = new ArrayList<List<Integer>>();
22-
23-
if(num.length < 4) return found;
24-
25-
HashMap<Integer, ArrayList<TwoSum>> cache = new HashMap<Integer, ArrayList<TwoSum>>();
26-
27-
Arrays.sort(num);
28-
29-
for(int i = 0; i < num.length; i++){
30-
for(int j = i + 1; j < num.length; j++){
31-
32-
int s = num[i] + num[j];
33-
TwoSum t = new TwoSum();
34-
35-
t.index1 = i;
36-
t.index2 = j;
37-
38-
ArrayList<TwoSum> l = cache.get(s);
39-
if(l == null){
40-
l = new ArrayList<TwoSum>();
41-
cache.put(s, l);
42-
}
43-
44-
l.add(t);
45-
}
46-
}
47-
48-
HashSet<String> block = new HashSet<String>();
49-
50-
for(Integer a : cache.keySet()){
51-
Integer b = target - a;
52-
53-
ArrayList<TwoSum> lsb = cache.get(b);
54-
if(lsb != null){
55-
ArrayList<TwoSum> lsa = cache.get(a);
56-
57-
for(TwoSum sa : lsa)
58-
for(TwoSum sb : lsb){
59-
60-
if(sa.overlap(sb)) continue;
61-
62-
Integer[] sol = new Integer[]{num[sa.index1], num[sa.index2], num[sb.index1], num[sb.index2]};
63-
Arrays.sort(sol);
64-
65-
String uid = Arrays.toString(sol);
66-
if(!block.contains(uid)){
67-
found.add(Arrays.asList(sol));
68-
69-
block.add(uid);
70-
}
71-
72-
73-
}
74-
75-
cache.put(a, null);
76-
cache.put(b, null);
77-
}
78-
}
79-
80-
81-
return found;
82-
}
83-
}
1+
public class Solution {
2+
3+
static class TwoSum {
4+
int index1;
5+
int index2;
6+
7+
boolean overlap(TwoSum other){
8+
if(this == other) return true;
9+
10+
if(index1 == other.index1) return true;
11+
if(index2 == other.index1) return true;
12+
13+
if(index1 == other.index2) return true;
14+
if(index2 == other.index2) return true;
15+
16+
return false;
17+
}
18+
}
19+
20+
public List<List<Integer>> fourSum(int[] num, int target) {
21+
ArrayList<List<Integer>> found = new ArrayList<List<Integer>>();
22+
23+
if(num.length < 4) return found;
24+
25+
HashMap<Integer, ArrayList<TwoSum>> cache = new HashMap<Integer, ArrayList<TwoSum>>();
26+
27+
Arrays.sort(num);
28+
29+
for(int i = 0; i < num.length; i++){
30+
for(int j = i + 1; j < num.length; j++){
31+
32+
int s = num[i] + num[j];
33+
TwoSum t = new TwoSum();
34+
35+
t.index1 = i;
36+
t.index2 = j;
37+
38+
ArrayList<TwoSum> l = cache.get(s);
39+
if(l == null){
40+
l = new ArrayList<TwoSum>();
41+
cache.put(s, l);
42+
}
43+
44+
l.add(t);
45+
}
46+
}
47+
48+
HashSet<String> block = new HashSet<String>();
49+
50+
for(Integer a : cache.keySet()){
51+
Integer b = target - a;
52+
53+
ArrayList<TwoSum> lsb = cache.get(b);
54+
if(lsb != null){
55+
ArrayList<TwoSum> lsa = cache.get(a);
56+
57+
for(TwoSum sa : lsa)
58+
for(TwoSum sb : lsb){
59+
60+
if(sa.overlap(sb)) continue;
61+
62+
Integer[] sol = new Integer[]{num[sa.index1], num[sa.index2], num[sb.index1], num[sb.index2]};
63+
Arrays.sort(sol);
64+
65+
String uid = Arrays.toString(sol);
66+
if(!block.contains(uid)){
67+
found.add(Arrays.asList(sol));
68+
69+
block.add(uid);
70+
}
71+
72+
73+
}
74+
75+
cache.put(a, null);
76+
cache.put(b, null);
77+
}
78+
}
79+
80+
81+
return found;
82+
}
83+
}
+35-35
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
public class Solution {
2-
public int threeSumClosest(int[] num, int target) {
3-
4-
if(num.length < 3) return 0;
5-
6-
Arrays.sort(num);
7-
8-
int pneg = 0 , ppos = num.length - 1;
9-
10-
int closest = num[0] + num[1] + num[2];
11-
12-
while(ppos > 0){
13-
while(pneg < ppos){
14-
int sum = num[pneg];
15-
sum += num[ppos];
16-
17-
for(int i = pneg + 1; i < ppos; i++){
18-
if(Math.abs(target - (num[i] + sum)) < Math.abs(target - closest) ){
19-
closest = num[i] + sum;
20-
}
21-
}
22-
23-
int old = num[pneg];
24-
while(pneg < ppos && num[pneg] == old) pneg++;
25-
}
26-
27-
pneg = 0;
28-
29-
int old = num[ppos];
30-
while(ppos > 0 && num[ppos] == old) ppos--;
31-
}
32-
33-
34-
return closest;
35-
}
1+
public class Solution {
2+
public int threeSumClosest(int[] num, int target) {
3+
4+
if(num.length < 3) return 0;
5+
6+
Arrays.sort(num);
7+
8+
int pneg = 0 , ppos = num.length - 1;
9+
10+
int closest = num[0] + num[1] + num[2];
11+
12+
while(ppos > 0){
13+
while(pneg < ppos){
14+
int sum = num[pneg];
15+
sum += num[ppos];
16+
17+
for(int i = pneg + 1; i < ppos; i++){
18+
if(Math.abs(target - (num[i] + sum)) < Math.abs(target - closest) ){
19+
closest = num[i] + sum;
20+
}
21+
}
22+
23+
int old = num[pneg];
24+
while(pneg < ppos && num[pneg] == old) pneg++;
25+
}
26+
27+
pneg = 0;
28+
29+
int old = num[ppos];
30+
while(ppos > 0 && num[ppos] == old) ppos--;
31+
}
32+
33+
34+
return closest;
35+
}
3636
}

0 commit comments

Comments
 (0)