package
0.0.0-20210911005019-8a26e672d2db
Repository: https://github.com/renyddd/golang.git
Documentation: pkg.go.dev

# README

nowcoder 牛客网刷体记录

在刚开始训练时,本地提供完整的可运行代码。 最好每章都能有必要的注释,或者加上一些 go 语言语法的拓展部分。

读取用户输入

使用fmt包中的Scanln函数:

var n1, n2 int
fmt.Scanln(&n1, &n2)

或者使用bufio包缓冲读写,待补充。

近期时间有限,一定要用在紧迫的技能上!

ListNode

合并链表

使用 new 为结构体变量分配内存,分配当前类型所属的零直:

var head = new(ListHead)
head := new(ListHead)

或者使用混合字面量语法(composite literal syntax)&struct1{1,nil},其为一种简写但底层还是在调用new,此时赋值的字段必须按照顺序来写。

当然这样是等价的new(ListHead), &ListHead{}

head := &ListHead{Val: 5, Next: nil}

为类型定义结构体工厂,工厂名以 new 或者 New 开头,一次来简单的实现构造函数:

func NewListNode(val int, next *ListNode) *ListNode {
        if val < 0 { 			// 强迫 Val 直大于零
                return nil
        }
        return &ListNode{Val: val, Next: next}
}

同样运用可见性规则(当标识符以大写字母开头则其对象可被外部包代码所使用),可以强制使用工厂函数。

# Packages

No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author