Go语言中文网 为您找到相关结果 21

leetcode刷题笔记(Golang)--11. Container With Most Water

题链接11. Container With Most Water Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. **Note: **You ...阅读全文

博文 2020-02-08 01:32:44 煮酒_zzh

如何让新站点1小时内快速被收录

每个站长刚刚建好一个站的时候都特别希望自己的网站被很快的收录。但是大部分人需要10几天甚至1个月才会被收了。但是有的几个小时就收录,甚至十多分钟就可以,是不是很神奇。这些是很有技巧性的。为什么搜索引擎收录新站点会有那么大的时间差距,那些1小时内被收录的网站究竟做了些什么手法? http://www.nss168.com/archives/46.htm...阅读全文

golang 的glide包管理使用技巧教程

安装glide ➜ wemall git:(master) ✗ go get github.com/Masterminds/glide ➜ wemall git:(master) ✗ go install github.com/Masterminds/glide ➜ wemall git:(master) ✗ glide init ➜ wemall git:(master) ✗ glide up [INFO] Loading mirrors from mirrors.yaml file[INFO] Downloading dependencies. Please wait...[INFO] --> Fetching updates for github.com/jinzhu/gorm[INF...阅读全文

博文 2017-09-25 13:30:02 jackluo

Go 语言的 10 个实用技巧

一句话技巧 把你面向对象的大脑扔到家里吧,去拥抱接口。 学习如何使用Go的方式做事,不要把别的的编程风格强行用在Go里面。 多用接口总比少用好。 拥抱这种简洁、并行、工整的语言。 阅读官网golang.org上所有的文档,真是棒呆了。 别忘了用gofmt。 多读源代码。 学习工具和组件,然后创造你自己的!码代码和学代码一样对成功必不可少。 学而不思则罔,思而不学则殆。《论语》 引入package的多种方式 有几种非常规方式来引入包(package)。接下来我会使用fmt来作为例子: import format "fmt" - 为fmt创造一个别名。把代码中所有使用到fmt的内容用format.代替fmt. import . "fmt" - 允许包内的内容不加fmt前缀而被被直接引用 impo...阅读全文

博文 2019-12-24 15:32:41 衣服里的吸引咒

leecode two sum golang解析

Leetcode上的two sum算法用golang实现 two sum问题 : Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1]. 解题一 一般思路: package main import ( "fmt" ) func twoSum(nums []int, target int) []int { for i, v1 := range nums { if i+1 != len(nums) { for j, v2 := range nums[i+1:] { if target == (v1 + v2) { return []int{i, i + j + 1...阅读全文

博文 2018-02-20 20:34:38 hades

【Leetcode】:22. Generate Parentheses 问题 in Go语言

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: "((()))", "(()())", "(())()", "()(())", "()()()" 解题思路:这道题和N-Queen问题非常类似,几乎是一样的解题模式。 首先需要明白,怎么放置括号是合法的,假设n=5的情况,已经合法的放置了4个括号,那么怎么判断下一个放什么括号合法呢? 放左括号:如果之前放置的左括号数>=n,那么一定不合法 放右括号:如果之前放置的左括号数<=之前放置的右括号数,那么...阅读全文

博文 2016-05-02 23:00:00 u013564276

[Go小技巧] 如何写很酷的连贯操作?

定义连贯操作的结构体方法 package toy type Toy struct { nick string shape string color string height int } func (t *Toy) SetNick(nick string) *Toy { t.nick = nick return t } func (t *Toy) SetShape(shape string) *Toy { t.shape = shape return t } func (t *Toy) SetColor(color string) *Toy { t.color = color return t } func (t *Toy) SetHeight(height int) *Toy { t.he...阅读全文

博文 2016-09-02 02:00:01 henrylee2cn

leetcode刷题笔记(Golang)--14. Longest Common Prefix

题链接14. Longest Common Prefix Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". Example 1: Input: ["flower","flow","flight"] Output: "fl" Example 2: Input: ["dog","racecar","car"] Output: "" Explanation: There is no common prefix among the input strings. No...阅读全文

博文 2020-02-08 01:32:44 煮酒_zzh

Golang if块小技巧

if result, errorMsg := Divide(100, 10); errorMsg == "" { fmt.Println("100/10 = ", result) } if _, errorMsg := Divide(100, 0); errorMsg != "" { fmt.Println("errorMsg is: ", errorMsg) } 等价于 result, errorMsg := Divide(100, 10) if errorMsg == "" { fmt.Println("100/10 = ", result) } result, errorMsg = Divide(100, 0) if errorMsg != "" { fmt.Println("erro...阅读全文

博文 2019-03-01 17:34:44 钾肥尔德

Go语言实践技巧(7)——value receiver和pointer receiver

Value receiver: func (u user) fun1() { .... } Pointer receiver: func (u *user) fun2() { .... } Value receiver操作的是值的拷贝,而pointer receiver操作的是实际的值。 用pointer去调用value receiver的方法,实际的操作是: (*p).fun1() 而用value去调用pointer receiver的方法,实际的操作是: (&v).fun2() 参考资料: Go in Action...阅读全文

博文 2017-06-24 19:19:59 肖楠

leetcode刷题笔记(Golang)--16. 3Sum Closest

题链接16. 3Sum Closest Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution. Example: Given array nums = [-1, 2, 1, -4], and target = 1. The sum that is closest to the target is 2....阅读全文

博文 2020-02-08 01:32:41 煮酒_zzh

golang 解题标准括号问题

·解题思路来源https://github.com/azl3979858... package main import "container/list" import "fmt" func main(){ s := "{{}}" m := "{{[()}]}" l := "{[(())]}" fmt.Println(check(s)) fmt.Println(check(m)) fmt.Println(check(l)) } func check(x string) bool { mapper := map[byte]byte{ '{':'}', '(':')', '[':']', } stack := list.New() //初始化栈 for _, v := range x { i :=...阅读全文

博文 2020-05-28 11:32:45 氓浅

leetcode刷题笔记(Golang)--15. 3Sum

题链接15. 3Sum Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: The solution set must not contain duplicate triplets. Example: Given array nums = [-1, 0, 1, 2, -1, -4], A solution set is: [ [-1, 0, 1], [-1, -1, 2] ] 解题思路:转化为n个2sum问题 f...阅读全文

博文 2020-02-08 01:32:42 煮酒_zzh

Go语言实用技巧

基础代码说明 time类:系统的时间类 time.second/minute/hour time.Duration能够对时间进行转换,默认开始是1ns,换算单位是1ms = 1000µs = 1000,000ns,往上到时间的那一层也能正常转换 time类能够自动转换时间,通用的是nuix的时间格式,不需要手动处理时间格式 strings类提供的split方法能够拆分字符串为字符串数组 golang的post的请求和接收,并对数据进行处理 post的发送 func HttpServerSender(data data.SenderData) { jsonss,err :=json.Marshal(data) if err != nil { fmt.Println(err.Error() ) ...阅读全文

博文 2019-01-02 12:34:45 木鱼cavalry