-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
80 lines (73 loc) · 1.93 KB
/
App.java
File metadata and controls
80 lines (73 loc) · 1.93 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
75
76
77
78
79
80
import java.util.*;
public class App {
public static void main(String[] args) throws Exception {
// int a =2;
// int b = 3;
// int c = gcd(a,b);
// System.out.println(c);
int[] a ={1,2,3,3,4};
// swap(1, 0, a);
// System.out.println(a);
exchange(a);
System.out.println(a);
}
public static int[] exchange(int[] nums) {
int i = 0,j=0;
while(i<=nums.length-1){
if((nums[i]& 1)!= 0){
int temp = nums[i];
nums[i]=nums[j];
nums[j]=temp;
j++;
}
++i;
}
return nums;
}
/**
* 返回最大公约数
* @param a
* @param b
* @return
*/
public static int gcd(int a,int b){
if(b==0){
return a;
}
return gcd(b,a%b);
}
/**
* 交换函数
*/
public static void swap(int i,int j ,int[] a) {
a[i]=a[i]^a[j];
a[j]=a[i]^a[j];
a[i]=a[i]^a[j];
}
class Solution {
public List<List<Integer>> levelOrder(TreeNode root) {
if (root == null) {
return null;
}
List<List<Integer>> levelOrder = new ArrayList<>();
Queue<TreeNode> queue = new ArrayDeque<>();
queue.add(root);
while (!queue.isEmpty()) {
int count = queue.size();
List<Integer> list = new ArrayList<>();
for (int i = 0; i < count; i++) {
TreeNode treeNode = queue.poll();
list.add(treeNode.val);
if (treeNode.left != null) {
queue.add(treeNode.left);
}
if (treeNode.right != null) {
queue.add(treeNode.right);
}
}
levelOrder.add(list);
}
return levelOrder;
}
}
}