Skip to content

Commit 0428b82

Browse files
add ZivkoTheCarpenter solution
1 parent f32a475 commit 0428b82

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

medium300/ZivkoTheCarpenter.java

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package medium300;
2+
3+
public class ZivkoTheCarpenter {
4+
public int getMinNails(int[] left, int[] right) {
5+
6+
for (int i = 0; i < left.length; i++)
7+
for (int j = 0; j < left.length; j++)
8+
if (left[i] > left[j]) {
9+
int tmp = left[i];
10+
left[i] = left[j];
11+
left[j] = tmp;
12+
tmp = right[i];
13+
right[i] = right[j];
14+
right[j] = tmp;
15+
}
16+
17+
boolean[] visited = new boolean[16];
18+
int cnt = 0;
19+
for (int i = 0; i < left.length; i++) {
20+
if (visited[i])
21+
continue;
22+
cnt++;
23+
for (int j = 0; j < left.length; j++) {
24+
if (left[i] > right[j] || right[i] < left[j])
25+
continue;
26+
else
27+
visited[j] = true;
28+
}
29+
}
30+
31+
return cnt;
32+
}
33+
34+
public static void main(String[] args) {
35+
ZivkoTheCarpenter z = new ZivkoTheCarpenter();
36+
System.out.println(z.getMinNails(new int[] { 49, 48, 8, 40, 26, 41, 49, 29, 23, 37 },
37+
new int[] { 51, 49, 9, 42, 28, 43, 50, 31, 25, 38 }));
38+
}
39+
}

0 commit comments

Comments
 (0)