当前位置:网站首页>微软100题-天天做-第11题
微软100题-天天做-第11题
2022-07-28 15:33:00 【51CTO】
课程内容:各种k8s部署方式。包括minikube部署,kubeadm部署,kubeasz部署,rancher部署,k3s部署。包括开发测试环境部署k8s,和生产环境部署k8s。
腾讯课堂连接地址https://ke.qq.com/course/484107?tuin=ba64518
介绍主要的k8s资源的使用配置和命令。包括configmap,pod,service,replicaset,namespace,deployment,daemonset,ingress,pv,pvc,sc,role,rolebinding,clusterrole,clusterrolebinding,secret,serviceaccount,statefulset,job,cronjob,podDisruptionbudget,podSecurityPolicy,networkPolicy,resourceQuota,limitrange,endpoint,event,conponentstatus,node,apiservice,controllerRevision等。
详细介绍helm命令,学习helm chart语法,编写helm chart。深入分析各项目源码,学习编写helm插件
————————————————------------------------------------------------------------------------------------------------------------------
第11题(树)
求二叉树中节点的最大距离...
如果我们把二叉树看成一个图,父子节点之间的连线看成是双向的,
我们姑且定义"距离"为两节点之间边的个数。
写一个程序,
求一棵二叉树中相距最远的两个节点之间的距离。
package
com.
microsoft;
import
java.
util.
Random;
public
class
MaxDistance {
private
Node
root;
private
Node
lineRoot;
public
MaxDistance(
int[]
data) {
for (
int
i
=
0;
i
<
data.
length;
i
++) {
Node
node
=
new
Node();
node.
value
=
data[
i];
node.
weight
=
0;
if (
root
==
null) {
root
=
node;
}
else {
insertNode(
root,
node);
}
}
}
private
void
computeRoot(){
int
maxWeight
=
0;
if(
root.
left
!=
null
&&
root.
right
!=
null){
maxWeight
=
root.
left.
weight
+
root.
right.
weight
+
1;
}
else
if(
root.
left
!=
null){
maxWeight
=
root.
left.
weight
+
1;
}
else
if(
root.
right
!=
null){
maxWeight
=
root.
right.
weight
+
1;
}
lineRoot
=
root;
computeRoot(
root,
maxWeight);
}
private
void
computeRoot(
Node
node,
int
weight){
int
maxWeight
=
0;
if(
node.
left
!=
null
&&
node.
right
!=
null){
maxWeight
=
node.
left.
weight
+
node.
right.
weight
+
1;
}
else
if(
node.
left
!=
null){
maxWeight
=
node.
left.
weight
+
1;
}
else
if(
node.
right
!=
null){
maxWeight
=
node.
right.
weight
+
1;
}
if(
maxWeight
>
weight){
weight
=
maxWeight;
lineRoot
=
node;
}
if(
node.
left
!=
null){
computeRoot(
node.
left,
weight);
}
if(
node.
right
!=
null){
computeRoot(
node.
right,
weight);
}
}
public
void
getDistance(){
computeRoot();
System.
out.
println(
lineRoot.
value);
lineRoot.
corss
=
true;
if(
lineRoot.
left
!=
null
&&
lineRoot.
right
!=
null){
lineRoot.
left.
corss
=
true;
lineRoot.
right.
corss
=
true;
markNode(
lineRoot.
left);
markNode(
lineRoot.
right);
}
else
if(
lineRoot.
left
!=
null){
lineRoot.
left.
corss
=
true;
markNode(
lineRoot.
left);
}
else
if(
lineRoot.
right
!=
null){
lineRoot.
right.
corss
=
true;
markNode(
lineRoot.
right);
}
printMaxDisLeftNode(
lineRoot.
left);
System.
out.
print(
lineRoot.
value
+
"=>");
printMaxDisRightNode(
lineRoot.
right);
System.
out.
println();
}
private
void
printMaxDisLeftNode(
Node
node){
if(
node
==
null){
return;
}
if(
node.
left
!=
null
&&
node.
left.
corss){
printMaxDisLeftNode(
node.
left);
}
else
if(
node.
right
!=
null
&&
node.
right.
corss){
printMaxDisLeftNode(
node.
right);
}
System.
out.
print(
node.
value
+
"=>");
}
private
void
printMaxDisRightNode(
Node
node){
if(
node
==
null){
return ;
}
System.
out.
print(
node.
value
+
"=>");
if(
node.
left
!=
null
&&
node.
left.
corss){
printMaxDisRightNode(
node.
left);
}
else
if(
node.
right
!=
null
&&
node.
right.
corss){
printMaxDisRightNode(
node.
right);
}
}
private
void
markNode(
Node
node){
if(
node
==
null){
return ;
}
if(
node.
left
!=
null
&&
node.
right
!=
null){
if(
node.
left.
weight
>
node.
right.
weight){
node.
left.
corss
=
true;
markNode(
node.
left);
}
else{
node.
right.
corss
=
true;
markNode(
node.
right);
}
}
else
if(
node.
left
!=
null){
node.
left.
corss
=
true;
markNode(
node.
left);
}
else
if(
node.
right
!=
null){
node.
right.
corss
=
true;
markNode(
node.
right);
}
}
private
void
insertNode(
Node
parent,
Node
node) {
int
random
=
new
Random().
nextInt(
2);
if (
parent
==
root
||
random
==
1) {
if (
parent.
left
!=
null) {
insertNode(
parent.
left,
node);
}
else {
parent.
left
=
node;
node.
parent
=
parent;
Node
n
=
node;
while (
n
!=
null) {
if (
n.
left
!=
null
&&
n.
right
!=
null) {
n.
weight
=
Math.
max(
n.
left.
weight,
n.
right.
weight)
+
1;
}
else
if (
n.
left
!=
null) {
n.
weight
=
n.
left.
weight
+
1;
}
else
if (
n.
right
!=
null) {
n.
weight
=
n.
right.
weight
+
1;
}
n
=
n.
parent;
}
}
}
else {
if (
parent.
right
!=
null) {
insertNode(
parent.
right,
node);
}
else {
parent.
right
=
node;
node.
parent
=
parent;
Node
n
=
node;
while (
n
!=
null) {
if (
n.
left
!=
null
&&
n.
right
!=
null) {
n.
weight
=
Math.
max(
n.
left.
weight,
n.
right.
weight)
+
1;
}
else
if (
n.
left
!=
null) {
n.
weight
=
n.
left.
weight
+
1;
}
else
if (
n.
right
!=
null) {
n.
weight
=
n.
right.
weight
+
1;
}
n
=
n.
parent;
}
}
}
}
public
void
print() {
Node
h
=
this.
root;
this.
print(
0,
h);
}
private
void
print(
int
level,
Node
node) {
if(
node
==
null){
return;
}
for (
int
i
=
0;
i
<
level;
i
++) {
System.
out.
format(
" ");
}
System.
out.
format(
"|");
for (
int
i
=
0;
i
<
level;
i
++) {
System.
out.
format(
"-");
}
System.
out.
format(
"%d%s%s%n",
node.
value,
","
+
node.
weight,
node.
corss
?
"M":
"");
print(
level
+
1,
node.
left);
print(
level
+
1,
node.
right);
}
private
class
Node {
private
Node
parent;
private
Node
left;
private
Node
right;
private
int
value;
private
boolean
corss;
private
int
weight;
}
public
static
void
main(
String[]
args) {
int[]
data
=
new
int[] {
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 };
MaxDistance
tree
=
new
MaxDistance(
data);
tree.
getDistance();
tree.
print();
}
}
- 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.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
- 180.
- 181.
- 182.
- 183.
- 184.
- 185.
- 186.
- 187.
- 188.
- 189.
- 190.
- 191.
- 192.
- 193.
- 194.
- 195.
- 196.
- 197.
- 198.
- 199.
- 200.
- 201.
- 202.
- 203.
- 204.
- 205.
- 206.
边栏推荐
猜你喜欢

加速投资的小红书,“病急乱投医”?

队列的介绍与实现(详解)

mysql 查看事件状态语句和修改办法

LwIP development | realize TCP server through socket

资本「断供」两年,我只能把公司卖了

The little red book of accelerating investment, "rush to medical treatment"?

魏建军骑宝马也追不上李书福

I came across Digital Phoenix coordinate Xuhui Meiluo city in Shanghai

关于web对接针式打印机问题,Lodop使用

Redis系列4:高可用之Sentinel(哨兵模式)
随机推荐
WSL+Valgrind+Clion
Early in the morning, pay Bora SMS to say that you won the "prize"? Dealing with server mining virus - kthreaddi
Let's learn the game of beating hamsters
R language ggplot2 visually draws line plots, and uses gghighlight package to highlight the lines that meet the combination judgment conditions in the line graphs (satisfies both condition a and b)
C language exception handling mechanism: jump function jump function setjmp/sigsetjmp and longjmp/siglongjmp
资本「断供」两年,我只能把公司卖了
PHP about problems such as memory overflow timeout caused by large amount of data exporting or traversing data
mysql查询 limit 1000,10 和limit 10 速度一样快吗?如果我要分页,我该怎么办?
What does it remote operation and maintenance mean? Which is the best remote operation and maintenance software?
加速投资的小红书,“病急乱投医”?
Qt学习之信号和槽机制
Rosen's QT journey 101 models and views in QT quick
Practical development tutorial of software problem repair tracking system (Part 1)
Thoughts on solving the pop-up of malicious computer advertisements
LwIP development | realize TCP server through socket
食品安全 | 这两类瓜果宜改善便秘 孕妇人群尤其建议
HDU1847解题思路
Redis系列4:高可用之Sentinel(哨兵模式)
Image semantic segmentation practice: tensorflow deeplobv3+ train your own dataset
The video Number finds the golden key, and Tiktok imitates the latecomers