-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path1033.java
More file actions
66 lines (61 loc) · 1.64 KB
/
1033.java
File metadata and controls
66 lines (61 loc) · 1.64 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public int[] numMovesStones(int a, int b, int c) {
int min = 0;
int max = 0;
int x = a;
int y = b;
if (a > b) {
x = b;
y = a;
}
int z = c;
if (c < x) {
z = y;
y = x;
x = c;
} else if (c < y) {
z = y;
y = c;
}
// System.out.println(""+ x + y + z) ;
max += z-x-2;
if (y-x == 2 || z-y == 2 || (y-x == 1 && z-y >1) || (z-y == 1 && y-x > 1))
min = 1;
else if (y-x >1 || z-y > 1)
min = 2;
return new int[] {min, max};
}
}
__________________________________________________________________________________________________
sample 32652 kb submission
class Solution {
public int[] numMovesStones(int a, int b, int c) {
if(a > b){
int temp = a;
a = b;
b = temp;
}
if(a > c){
int temp = a;
a = c;
c = temp;
}
if(c < b){
int temp = c;
c = b;
b = temp;
}
int maxStep = b - a - 1 + c - b - 1;
int minStep = 2;
if(b - a <= 2 || c - b <= 2){
minStep = 1;
}
if(b - a == 1 && c - b == 1){
minStep = 0;
}
return new int[]{minStep, maxStep};
}
}
__________________________________________________________________________________________________