- 博客(29)
- 收藏
- 关注
原创 [Golang]传递一个切片(slice)和使用变参(...)语法传递多个参数之间的区别
在 Go 中,传递一个切片(slice)和使用变参(…)语法传递多个参数之间有一些关键区别。
2024-11-24 16:27:25
564
1
原创 OddOccurrencesInArray
Desc:A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired.For example,
2021-12-12 17:06:08
510
原创 1. CyclicRotation Rotate an array to the right by a given number of steps.
An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9,
2021-12-12 17:02:31
456
原创 反转链表 面试题&leetcode
反转链表solution/** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */func reverseList(head *ListNode) *ListNode { result :=&ListNode{0,nil} cur :=head for cur !=nil { t
2021-11-27 21:42:17
162
原创 线程是如何调度的?面试题 003
计算机通常只有一个cpu,在这种情况下,所谓多线程从宏观上看是并发进行的,但是微观下还是串行的,因为同一时刻只能有一个线程运行。先到先服务(FCFS)。。。短作业优先(SJF)调度算法。。。优先级调度算法。。。高响应比优先调度算法。。。时间轮片调度算法。。。多级反馈队列调度算法。。。待完善...
2021-11-23 23:12:34
406
原创 go array和slice的区别 golang面试题 002
002 go array和slice的区别相同点都是属于集合类的类型,用来存储同一种类型的数据或者元素不同点数组的长度固定,数组是值类型(值类型有基本数据类型,结构体类型),数组的空余位置用0填补,不允许数组越界。slice的值长度可变,属于引用类型(引用类型:字典类型,通道类型,函数类型)切片是引用传递,所以它们不需要使用额外的内存并且比使用数组更有效率。如果传递的是引用类型,那么就是“传引用”,如果传递的是值类型,那么就是“传值”(会把以前的数据复制一遍)数组长度在声明的时候就必须给定,
2021-11-23 09:37:30
470
原创 golang面试题 001
001 go channel close后读的问题golang channel关闭后,其中剩余的数据,是可以继续读取的。请看下面的测试例子。创建一个带有缓冲的channel,向channel中发送数据,然后关闭channel,最后,从channel中读取数据,输出结果。package mainimport "fmt"//go channel close后读的问题func main() { ch := make(chan string, 3) ch <- "test1" ch
2021-11-22 23:59:28
6582
原创 golang map
https://zhuanlan.zhihu.com/p/27108356https://zhuanlan.zhihu.com/p/364904972https://zhuanlan.zhihu.com/p/273666774https://zhuanlan.zhihu.com/p/157465066https://zhuanlan.zhihu.com/p/102385081
2021-11-21 23:33:17
216
原创 删除链表的倒数第 N 个结点 golang
19 删除链表的倒数第 N 个结点/** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */func removeNthFromEnd(head *ListNode, n int) *ListNode { result :=&ListNode{0,head} var ptr1,ptr2 *ListNode=h
2021-11-21 18:05:02
399
原创 不同的二叉搜索树 II golang
95 不同的二叉搜索树 II Solution/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func generateTrees(n int) []*TreeNode { var arr []int i :=1 for i <= n {
2021-11-21 12:51:27
170
原创 二叉树展开为链表 golang
二叉树展开为链表/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func flatten(root *TreeNode) { nodes :=PreOrder(root) i:=1 p :=root root.Left =nil for ;
2021-11-21 00:18:50
425
原创 有序链表转换二叉搜索树 golang
有序链表转换二叉搜索树/** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } *//** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode
2021-11-21 00:16:04
500
原创 从前序与中序遍历序列构造二叉树 golang
105 从前序与中序遍历序列构造二叉树 方法一:递归思路对于任意一颗树而言,前序遍历的形式是[ 根, [左子树的前序遍历结果], [右子树的前序遍历结果] ]即根节点总是前序遍历中的第一个节点。而中序遍历的形式是[ [左子树的中序遍历结果], 根, [右子树的中序遍历结果] ]只要我们在中序遍历中定位到根节点,那么我们就可以分别知道左子树和右子树中的节点数目。由于同一颗子树的前序遍历和中序遍历的长度显然是相同的,因此我们就可以对应到前序遍历的结果中,对上述形式中的所有左右括号进行定位。
2021-11-20 17:37:36
689
原创 golang slice
Go 语言切片(Slice)Go 语言切片是对数组的抽象。Go 数组的长度不可改变,在特定场景中这样的集合就不太适用,Go 中提供了一种灵活,功能强悍的内置类型切片(“动态数组”),与数组相比切片的长度是不固定的,可以追加元素,在追加时可能使切片的容量增大。slice的基本信息可以从下面这个link看到slice 菜鸟编程Go Slice探秘——slice作为函数参数传递时,若修改函数中的slice,到底会不会改变原slice的值?Anaswer空(nil)切片一个切片在未初始化之前默认为
2021-11-19 16:22:51
126
原创 由遍历序列构造二叉树
#mermaid-svg-xWjAEWl1hbPI57Dd .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-xWjAEWl1hbPI57Dd .label text{fill:#333}#mermaid-svg-xWjAEWl1hbPI57Dd .node rect,#mermaid-svg-xWjAEWl1hb
2021-11-19 00:03:33
254
原创 Golang VScode debug设置
尝试vscode debug ,但是遇到下面错误DAP server listening at: 127.0.0.1:62253Build Error: go build -o C:\GoProject\kb-api-gateway\src\__debug_bin.exe -gcflags all=-N -l .\server.gogo: gopkg.in/guregu/null.v4@v4.0.0: missing go.sum entry; to add it: go mod download
2021-11-18 09:41:10
1668
原创 平衡二叉树 golang
平衡二叉树给定一个二叉树,判断它是否是高度平衡的二叉树。本题中,一棵高度平衡二叉树定义为:一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1 。/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ //自下往顶func isBalanced(root *TreeNod
2021-11-17 23:28:55
194
原创 二叉树的最大深度 golang
104 二叉树的最大深度给定一个二叉树,找出其最大深度。二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func maxDepth(root *TreeNode) int { if root == nil {
2021-11-17 16:16:13
158
原创 二叉树的层序遍历 golang
二叉树的层序遍历给你一个二叉树,请你返回其按 层序遍历 得到的节点值。 (即逐层地,从左到右访问所有节点)。/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func levelOrder(root *TreeNode) [][]int { result :=[][]int{
2021-11-17 15:44:34
498
原创 对称二叉树 golang
对称二叉树给定一个二叉树,检查它是否是镜像对称的。/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func isSymmetric(root *TreeNode) bool { // var check func(node1,node2 *TreeNode) bool
2021-11-17 14:48:16
287
原创 相同的树 golang
100. 相同的树给你两棵二叉树的根节点 p 和 q ,编写一个函数来检验这两棵树是否相同。如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func isSameTree(p *TreeNode, q *TreeN
2021-11-17 14:09:19
101
原创 二叉树中序遍历 golang
LeetCode94给定一个二叉树的根节点 root ,返回它的 中序 遍历。/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */func inorderTraversal(root *TreeNode) []int { var result []int var d
2021-11-17 13:57:20
277
原创 parsing time “\“\““ as “\“2006-01-02T15:04:05Z07:00\““: cannot parse “\““ as “2006“
I encounter the below error when I want to parse such string to struct.parsing time “”"" as ““2006-01-02T15:04:05Z07:00"”: cannot parse “”” as "2006"package mainimport ( "fmt" "time" "encoding/json")func main() { s :=`[ {"name":"test1","expireA
2021-11-17 11:36:34
5019
原创 Custom JSON Marshalling&UnMarshalling in Go
We know that through tags, we can conditionally customize the way of Go JSON serialization, such as json:",omitempty".We know that through tags, we can conditionally customize the way of Go JSON serialization, such as json:",omitempty". When the value of
2021-11-17 10:31:18
154
原创 Golang VS Code 中的代码自动补全和自动导入包
Golang VS Code 中的代码自动补全和自动导入包VSCode 必须安装以下插件:首先你必须安装 Golang 插件,然后再给 Go 安装工具包。在 VS Code 中,使用快捷键:command(windows ctrl)+shift+P,然后键入:go:install/update tools,将所有 16 个插件都勾选上,然后点击 OK 即开始安装。Installing 16 tools at /Users/maiyang/develop/goworkspace//bingoc
2021-01-20 01:15:11
5411
原创 centos7查存不到ip,输入vi /etc/sysconfig/network-scripts/ifcfg-eth0修改,但是后显示是空白
打开linux系统但是 查询不到ip可以通过ifconfig -a或者 ip addr 查询后面网上查询后说是可以通过更改文件,通过命令 vi /etc/sysconfig/network-scripts/ifcfg-eth0但是我打开后是空白的,无法编辑第一步,确认vim编辑器是否安装,确认无误后打开后还是没有内容这是因为:你是不能完全的照搬别人电脑上的显示的。操作系统可能不同...
2019-11-24 15:33:49
13002
5
原创 解决:Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2
mvn 上传项目到服务器后发现报错如下错误代码400 首先想到的是账号密码有无问题 反复再三确认后并无问题首先尝试改了jre路径没有用增加这两行代码后上传成功build success...
2019-11-23 02:14:14
7606
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人