微软100题-天天做-第四题

发布一个k8s部署视频:https://edu.youkuaiyun.com/course/detail/26967

课程内容:各种k8s部署方式。包括minikube部署,kubeadm部署,kubeasz部署,rancher部署,k3s部署。包括开发测试环境部署k8s,和生产环境部署k8s。

腾讯课堂连接地址https://ke.qq.com/course/478827?taid=4373109931462251&tuin=ba64518

第二个视频发布  https://edu.youkuaiyun.com/course/detail/27109

腾讯课堂连接地址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等。

第三个视频发布:https://edu.youkuaiyun.com/course/detail/27574

详细介绍helm命令,学习helm chart语法,编写helm chart。深入分析各项目源码,学习编写helm插件
————————————————------------------------------------------------------------------------------------------------------------------

4.在二元树中找出和为某一值的所有路径(树)

题目:输入一个整数和一棵二元树。
从树的根结点开始往下访问一直到叶结点所经过的所有结点形成一条路径。
打印出和与输入整数相等的所有路径。
例如 输入整数22和如下二元树
    10  
  /   /   
 5    12   
/ \     
4  7
则打印出两条路径:10, 12和10, 5, 7。

二元树节点的数据结构定义为:
struct BinaryTreeNode // a node in the binary tree
{
int m_nValue; // value of node
BinaryTreeNode *m_pLeft; // left child of node
BinaryTreeNode *m_pRight; // right child of node
};

 

 

package com.microsoft;

import java.util.Random;

public class ValuePathTree {
	private Node root;

	public ValuePathTree(int[] data) {
		for (int i = 0; i < data.length; i++) {
			Node node = new Node();
			node.value = data[i];
			node.leaf = true;
			insert(node);
		}
	}

	public void insert(Node node) {
		insert(root, node, true);
	}

	public void insert(Node parent, Node node, boolean left) {
		if (parent != root && parent.leaf && left) {
			parent.leaf = false;
			parent.left = node;
			node.parent = parent;
			int weight = node.value;
			Node p = node.parent;
			node.weight = weight + p.weight;
			return;
		} else if (parent != root && parent.leaf && !left) {
			parent.leaf = false;
			parent.right = node;
			node.parent = parent;
			int weight = node.value;
			Node p = node.parent;
			node.weight = weight + p.weight;
			return;
		}
		if (parent == null) {
			root = node;
			node.weight = node.value;
			return;
		}
		int random = new Random().nextInt(2);
		if (random == 1) {
			if (parent.left == null) {
				parent.left = node;
				parent.leaf = false;
				node.parent = parent;
				int weight = node.value;
				Node p = node.parent;
				node.weight = weight + p.weight;
			} else {
				insert(parent.left, node, true);
			}

		} else {
			if (parent.right == null) {
				parent.right = node;
				parent.leaf = false;
				node.parent = parent;
				int weight = node.value;
				Node p = node.parent;
				node.weight = weight + p.weight;
			} else {
				insert(parent.right, node, false);
			}

		}
	}

	public void print() {
		Node h = this.root;
		this.print(0, h);
	}

	private void print(int level, Node node) {
		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%n", node.value, node.weight);
		Node left = node.left;
		Node right = node.right;
		if (left != null) {
			print(level + 1, left);
		}
		if (right != null) {
			print(level + 1, right);
		}
	}

	private class Node {
		private Node parent;
		private Node left;
		private Node right;
		private boolean leaf;
		private int value;
		private int weight;
	}
	
	public void printPath(int weight){
		printPath(root,weight);
	}
	
	public void printPath(Node node,int weight){
		if(node==null){
			return;
		}
		if(!node.leaf){
			if(node.weight>weight){
				return;
			}else{
				printPath(node.left,weight);
				printPath(node.right,weight);
			}
		}else{
			if(node.weight==weight){
				StringBuffer sb=new StringBuffer();
				Node n=node;
				while(n!=null){
					sb.append(n.value+"-");
					n=n.parent;
				}
				sb.reverse();
				System.out.println(sb.toString());
				return;
			}else{
				return;
			}
		}
	}

	public static void main(String[] args) {
		int[] data = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,1,2,3,4,5,6,7 };
		ValuePathTree tree = new ValuePathTree(data);
		tree.print();
		tree.printPath(14);
	}

}

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hxpjava1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值