数组与切片

以前粗学时并没有留意 Golang 的数组,一直以为只有切片。

今天看《Go语言实践》时才发现 Golang 也有数组。与切片的区别是定义时指定长度(例如长度为4的 int 型数组var array [4]int)。

数组赋值时会拷贝整个数组,所以作为参数传递时也会完整拷贝,要考虑性能合理使用,必要时可以使用指针。

以下代码便于理解数组和切片:

Continue reading

Reverse Nodes in k-Group

Description

Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.

k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.

You may not alter the values in the nodes, only nodes itself may be changed.

Only constant memory is allowed.

For example,

Given this linked list: 1->2->3->4->5

For k = 2, you should return: 2->1->4->3->5

For k = 3, you should return: 3->2->1->4->5

Continue reading

Author's picture

SelFree

城市永远年轻,而我们终将老去

Programer

ChengDu