-
Notifications
You must be signed in to change notification settings - Fork 0
/
codingbat_most_ridiculous_code
58 lines (58 loc) · 1.34 KB
/
codingbat_most_ridiculous_code
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
public int[] fix45(int[] nums) {
int idx = 0;
boolean found4;
boolean found5;
while(idx < nums.length){
if(nums[idx] == 5){
int innerIdx = idx + 1;
found4 = false;
while((!found4) && (innerIdx < nums.length)){
if(nums[innerIdx] == 4){
found4 = true;
boolean notFound45 = true;
int innerIdx2 = innerIdx + 1;
while((notFound45) && (innerIdx2 < nums.length)){
if((nums[innerIdx2] != 4) && (nums[innerIdx2] != 5)){
notFound45 = false;
int temp = nums[idx];
nums[idx] = nums[innerIdx2];
nums[innerIdx2] = temp;
}
else{
innerIdx2++;
}
}
}
else{
innerIdx++;
}
}
idx++;
}
else if(nums[idx] == 4){
int innerIdx = idx + 1;
found5 = false;
while((!found5) && (innerIdx < nums.length)){
if(nums[innerIdx] == 5){
found5 = true;
if(innerIdx != idx + 1){
int temp = nums[idx + 1];
nums[idx + 1] = nums[innerIdx];
nums[innerIdx] = temp;
}
else{
innerIdx = idx + 2;
}
}
else{
innerIdx++;
}
}
idx += 2;
}
else{
idx++;
}
}
return nums;
}