题目如下: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric: eg: 1 / \ 2 2 / \ /… 阅读全文
[LeetCode每日一题]100. Same Tree
题目如下: Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical and the nodes have the same value. Leet… 阅读全文
[LeetCode每日一题]99. Recover Binary Search Tree
题目如下: Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. LeetCode-99 Recover Binary Search Tree 该题给定一棵二叉搜索树,树中正好有两个元素放反了,要求我们恢复这棵二叉搜索树。… 阅读全文
http协议下域名访问网站失败的解决方法
安装firewallD更换SSH端口后,发现使用http协议+www域名访问网站失败,而不带www的域名和ip:80直接访问都可以访问。 开始时认为是DNS解析的问题,一顿操作之后,发现没什么用。。。。 后来顿悟,遂去开放防火墙80端口,执行以下命令: firewall-cmd –permanent –zone=public –add-port=80/tcp 如果你的443端口没开,… 阅读全文
CentOS7安装firewalld并替换SSH默认的22端口
SSH登录验证成功后,您将看到以下消息: Last login: Mon Jul 29 23:08:52 2019 from xxx.xxx.xxx.xxx. Last failed login: Sun Jul 21 22:02:31 2019 from xxx.xxx.xxx.xxx on ssh:notty There were 15922 failed login attempts sin… 阅读全文
LeetCode-1 Two Sum 解析
题目: 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。 你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。 示例: [go]给定 nums = [2, 7, 11, 15], target = 9 因为 nums[0] + nums[1] = 2 + 7 = 9 所以返回 [0, 1][/go… 阅读全文
Go内建容器之映射(map)
映射是一种数据结构,用于存储一系列无序的键值对。 注: 1.map内部使用Hash表 2.除了slice,map,function的内建类型都可以作为map的key 3.struct类型不包含上述字段,也可作为key 创建和初始化 使用make声明map [go]m := make(map[string]int) //创建一个map,key的类型为string,value的类型为int[/go] … 阅读全文
Go内建容器之切片(slice)
切片(slice)是一种数据结构,这种数据结构便于使用和管理数据集合。切片是围绕动态数组的概念构建的,可以按需自动增长和缩小。切片的动态增长是通过内置函数append来实现的,这个函数可以快速且高效地增长切片。还可以通过对切片的再次切片来缩小一个切片的大小。因为切片的底层内存也是在连续块中分配的,所以切片还能获得索引、迭代、及为垃圾回收优化的好处。 slice的创建和初始化 1.通过数组创建 [g… 阅读全文
Go内建容器之数组
数组的声明 [go]var arr1 [5]int arr2 := [3]int{1, 3, 5} arr3 := […]int{2, 4, 6, 8, 10} var xy [3][4]bool //三行四列的二维数组[/go] 数组的遍历 [go]func traverse(arr *[5]int) { for i, v := range arr { //i为元素… 阅读全文
Go语法之for循环
示例 计算从1加到100 [go]sum := 0 for i:=1;i<=100;i++ { sum += i } fmt.Println(sum)[/go] 注意:for的条件不用加括号 for的条件里不写分号,相当于其他语言的while 改写上例片段 [go]sum :=0 i:=1 for i <= 100 { sum+=i i++ } fmt.Println(sum)[/go… 阅读全文