-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay01.java
More file actions
74 lines (72 loc) · 2.07 KB
/
Day01.java
File metadata and controls
74 lines (72 loc) · 2.07 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
67
68
69
70
71
72
73
74
package 比特笔试强训;
import java.util.ArrayList;
public class Day01 {
public static void main(String[] args) {
ArrayList<Integer> arrayList = new ArrayList<>();
arrayList.add(5);
arrayList.add(1);
arrayList.add(2);
arrayList.add(3);
arrayList.add(4);
System.out.println(minNumberInRotateArray(arrayList));
}
public static int[] reOrderArrayTwo (int[] array) {
// write code here
if (array==null || array.length==1){
return array;
}
int left = 0;
int right = array.length-1;
while (left<right){
if (array[left]%2==0 && array[right]%2!=0){
int tmp = array[left];
array[left]=array[right];
array[right]=tmp;
left++;
right--;
}
if (array[left]%2!=0){
left++;
}
if (array[right]%2==0){
right--;
}
}
return array;
}
public static int minNumberInRotateArray(ArrayList<Integer> array) {
int left = 0;
int right =array.size()-1;
while (left<right){
int mid = left+(right-left)/2;
if (array.get(mid)>array.get(right)){
left=mid+1;
}else if (array.get(mid)<array.get(right)){
right=mid;
}else {
right--;
}
}
return array.get(left);
}
public boolean Find(int target, int [][] array) {
int row = array.length;
int col = array[0].length;
if (row==0 || col==0){
return false;
}
row = 0;
col = array[0].length-1;
while (row<array.length && col>=0){
int cur = array[row][col];
if (cur<target){
row++;
}else if (cur>target){
col--;
}else {
return true;
}
}
return false;
}
}