提示
以下内容的目的,只是为了学习合法的知识
shsupervisor:要安装的软件的名称。 supervisord:装好supervisor软件后,supervisord用于启动supervisor服务。 supervisorctl:用于管理supervisor配置文件中program。
使用yum命令安装 切换为root用户
shyum install epel-release # 如果已安装EPEL源,请跳过
yum install -y supervisor
systemctl enable supervisord # 开机自启动
systemctl start supervisord # 启动supervisord服务
systemctl status supervisord # 查看supervisord服务状态
ps -ef|grep supervisord # 查看是否存在supervisord进程
相关信息
给定一个二叉树, 找到该树中两个指定节点的最近公共祖先。
jspackage main
import (
"fmt"
)
// 给定一个二叉树, 找到该树中两个指定节点的最近公共祖先。
// 最近公共祖先的定义:“对于有根树 T 的两个结点 p、q,最近公共祖先表示为一个结点 x,
// 满足 x 是 p、q 的祖先且 x 的深度尽可能大(一个节点也可以是它自己的祖先)。”
// 例如,如下二叉树: Integer[] levelOrder = {3,5,1,6,2,0,8,null,null,7,4};
// 3
// 5 1
// 6 2 0 8
// 7 4
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
func main() {
// 构建二叉树
root := &TreeNode{Val: 3}
root.Left = &TreeNode{Val: 5}
root.Right = &TreeNode{Val: 1}
root.Left.Left = &TreeNode{Val: 6}
root.Left.Right = &TreeNode{Val: 2}
root.Right.Left = &TreeNode{Val: 0}
root.Right.Right = &TreeNode{Val: 8}
root.Left.Right.Left = &TreeNode{Val: 7}
root.Left.Right.Right = &TreeNode{Val: 4}
// 测试最近公共祖先
p := root.Left.Right.Left
q := root.Left.Right.Right
lca := lowestCommonAncestor(root, p, q)
fmt.Println("最近公共祖先:", lca.Val)
// fmt.Println("Hello world!")
}
func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode {
if root == nil || root == p || root == q {
return root
}
left := lowestCommonAncestor(root.Left, p, q)
right := lowestCommonAncestor(root.Right, p, q)
if left != nil && right != nil {
return root
}
if left != nil {
return left
}
return right
}
相关信息
接雨水,这道题最大的问题在于理解怎么才能接到雨水
接雨水其实就是看当前位置的左右是否存在格挡,存在格挡可以存雨水,能存放的最大容积为左右出现的格挡的最大高度
第一步 声明变量初始值 left right maxLeft Maxleft res
第二步 从左右两边开始对比: for left < right {}
第三步 if height[left] < height[right] 则处理左边,否则处理右边
第四步 处理左边 如果当前位置(left)大于等于 maxLeft 则更新maxLeft 否则说明左边的高度是超出当前位置的,可以进行容积增加: maxLeft - height[left]
右边的逻辑和左边一样,发现右边的格挡更高,则增加高度差,否则更新高度最大值(当前值比maxRight更大)
jsfunc trap(height []int) int {
left, right := 0, len(height)-1
leftMax, rightMax := 0, 0
res := 0
for left < right {
if height[left] < height[right] {
if height[left] >= leftMax {
leftMax = height[left]
} else {
res += leftMax - height[left]
}
left++
} else {
if height[right] >= rightMax {
rightMax = height[right]
} else {
res += rightMax - height[right]
}
right--
}
}
return res
}