Skip to content

Commit 0f0fde1

Browse files
committed
添加逻辑非运算符
1 parent 6a78cff commit 0f0fde1

7 files changed

Lines changed: 76 additions & 4 deletions

File tree

360 Bytes
Binary file not shown.
559 Bytes
Binary file not shown.
Binary file not shown.
1.34 KB
Binary file not shown.

‎src/com/duweri/interview/BitCompute.java‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,27 @@ public static void main(String[] args) {
1010
//异或
1111
int a = 8;//1000
1212
int b = 9;//1001
13-
System.out.println(a^b);
13+
System.out.println("a^b = "+(a^b));
1414

1515
int x = 15;//01111=1+2+4+8
1616
int y = 23;//10111=1+2+4+16
17-
System.out.println(x^y);
17+
System.out.println("x^y = "+(x^y));
1818

1919
//与运算
20-
System.out.println(x&y);
20+
System.out.println("x&y = "+(x&y));
2121

2222
//或运算
23-
System.out.println(x|y);
23+
System.out.println("x|y = "+ (x|y));
2424

2525
//左右移运算
26+
System.out.println("8>>2 = "+(8>>2));
27+
System.out.println("8<<2 = "+(8<<2));
28+
29+
//~ 原码01000放进计算机用补码:01000,取反计算:10111(这是补码),输出源码(取反加1,符号位不变):11001
30+
System.out.println("~ = "+(~8));
31+
32+
System.out.println("8>>>2="+(8>>>2));
33+
2634
}
2735

2836
}

‎src/com/duweri/interview/Test.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.duweri.interview;
2+
3+
public class Test {
4+
5+
/**
6+
* @param args
7+
*/
8+
public static void main(String[] args) {
9+
10+
int[][] arr = new int[3][4];
11+
12+
System.out.println(arr.length);
13+
14+
15+
}
16+
17+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.duweri.interview.datastructure;
2+
3+
4+
/**
5+
* 已知前序遍历和后续遍历重建二叉树
6+
* @author 杜伟
7+
*/
8+
public class ReBuildBinaryTree {
9+
10+
static class TreeNode{
11+
int val;
12+
TreeNode left;
13+
TreeNode right;
14+
TreeNode(int x){val = x;}
15+
}
16+
17+
public TreeNode reConstructBinaryTree(int [] pre,int [] in) {
18+
TreeNode root=reConstructBinaryTree(pre,0,pre.length-1,in,0,in.length-1);
19+
return root;
20+
}
21+
//前序遍历{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6}
22+
private TreeNode reConstructBinaryTree(int [] pre,int startPre,int endPre,int [] in,int startIn,int endIn) {
23+
24+
if(startPre>endPre||startIn>endIn)
25+
return null;
26+
TreeNode root=new TreeNode(pre[startPre]);//前序遍历的第一个结点
27+
28+
for(int i=startIn;i<=endIn;i++){//遍历中序数组
29+
if(in[i]==pre[startPre]){ //如果中序的某节点和前序一样
30+
//递归左边
31+
root.left=reConstructBinaryTree(pre,startPre+1,startPre+i-startIn,in,startIn,i-1);
32+
//递归右边
33+
root.right=reConstructBinaryTree(pre,i-startIn+startPre+1,endPre,in,i+1,endIn);
34+
}
35+
}//循环完数组结束
36+
37+
return root;//返回根节点
38+
}
39+
40+
41+
42+
43+
public static void main(String[] args) {
44+
45+
}
46+
47+
}

0 commit comments

Comments
 (0)