
Golang
文章平均质量分 76
Better_JH
这个作者很懒,什么都没留下…
展开
-
Golang算法
func twoSum(nums []int, target int) []int { container := map[int]int{} for i,v := range nums { tmp := target - v if v, ok := container[tmp]; ok { return []int{v, i} } conta...原创 2018-12-27 15:36:04 · 448 阅读 · 0 评论 -
字符串的全排列&字符串的子集
//全排列func permute(nums []int) [][]int { ret := make([][]int,0) permute_(nums,0,&ret) return ret}func permute_(nums []int, begin int, ret *[][]int){ if begin >= len(nums){ ...原创 2019-03-02 21:22:44 · 652 阅读 · 0 评论 -
container/heap包的使用
package mainimport ( "fmt" "container/heap")type heap_ []intfunc (h heap_)Len() int { return len(h)}func (h heap_)Less(i,j int) bool { return h[i]<h[j]}func (h heap_)Swap(i,j int) { h[...原创 2019-02-14 16:29:31 · 380 阅读 · 0 评论 -
list
package main import ( "fmt")type Node struct { Data int Next *Node}func NewNode(data int)*Node{ return &Node{Data:data,Next:nil}}type List struct{ Root *Node}func NewList()*List{ v...原创 2018-12-27 15:34:32 · 300 阅读 · 0 评论 -
树的创建及遍历
//treepackage mainimport ( _"strings" "reflect" "fmt" "test/stackqueue")type Node struct { Data interface{} LChild *Node RChild *Node}func原创 2018-12-27 15:35:29 · 301 阅读 · 0 评论 -
优先级队列
package main import ( "container/heap" "fmt")type Item struct{ value string priority int idx int//item在heap中的索引}type queue []*Itemfunc (q queue) Len() int{ return len(q)}func (q queue) S...原创 2018-12-27 15:35:10 · 315 阅读 · 0 评论 -
字典树
package main import ( "fmt")type TrieNode struct { Child map[interface{}]*TrieNode IsEnd bool}func NewTrieNode()*TrieNode{ return &TrieNode{Child:make(map[interface{}]*TrieNode),IsEnd:fal...原创 2018-12-27 15:35:20 · 289 阅读 · 0 评论 -
队列的实现
//采用切片作为底层结构package main import ( "reflect" "fmt")type Queue struct { Values []interface{} Type reflect.Type}//初始化一个队列func NewQueue(valueType reflect.Type)*Queue{ return &a原创 2018-12-27 15:35:39 · 261 阅读 · 0 评论 -
栈的实现
//采用切片作为底层结构,也可以使用container/list包,更为简洁package main import ( "reflect" "fmt")type Stack struct { Values []interface{} Type reflect.Type}func NewStack(valueType r原创 2018-12-27 15:35:47 · 254 阅读 · 0 评论 -
排序
//插入func Insert(arr []int) { for i := 1; i < len(arr); i++ { tmp := arr[i] end := i - 1 //找插入位置&搬移 for ; end >= 0; end-- { if tmp &am原创 2018-12-27 15:35:55 · 273 阅读 · 0 评论