{"id":15399484,"url":"https://github.com/chai2010/leetcode-go","last_synced_at":"2025-04-15T22:31:06.180Z","repository":{"id":77627723,"uuid":"165463957","full_name":"chai2010/leetcode-go","owner":"chai2010","description":":computer:LeetCode练习, Go语言版本","archived":false,"fork":false,"pushed_at":"2019-01-15T00:44:35.000Z","size":51,"stargazers_count":24,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-06T07:37:24.748Z","etag":null,"topics":["algorithm","go","golang","leetcode"],"latest_commit_sha":null,"homepage":"https://leetcode-cn.com/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chai2010.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-13T04:03:03.000Z","updated_at":"2022-06-29T11:57:00.000Z","dependencies_parsed_at":"2024-03-09T03:31:58.888Z","dependency_job_id":null,"html_url":"https://github.com/chai2010/leetcode-go","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chai2010%2Fleetcode-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chai2010%2Fleetcode-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chai2010%2Fleetcode-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chai2010%2Fleetcode-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chai2010","download_url":"https://codeload.github.com/chai2010/leetcode-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249165977,"owners_count":21223358,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","go","golang","leetcode"],"created_at":"2024-10-01T15:49:05.066Z","updated_at":"2025-04-15T22:31:05.802Z","avatar_url":"https://github.com/chai2010.png","language":"Go","readme":"# leetcode-go\n\n[![Build Status](https://travis-ci.org/chai2010/leetcode-go.svg)](https://travis-ci.org/chai2010/leetcode-go)\n[![Go Report Card](https://goreportcard.com/badge/github.com/chai2010/leetcode-go)](https://goreportcard.com/report/github.com/chai2010/leetcode-go)\n[![License](http://img.shields.io/badge/license-BSD-blue.svg)](https://github.com/chai2010/leetcode-go/blob/master/LICENSE)\n\n算法之神Donald Knuth说过：过早优化是万恶之源。Go语言的哲学是：Less is more。根据Go语言哲学我们可以推导出以下推论：\n\n- Slow is fast：代码写的慢一点，代码执行可以变得快一点\n- Slow is fast：如果程序跑的慢一点，代码可以写的快一点\n- Fast is slow：代码写的很快，那么运行就很容易变慢，同时会拖累项目开发进度变慢\n- Fast is slow：如果程序跑的快，写代码就很容易变慢\n- 百米赛跑的冠军注定赢不了马拉松的冠军\n\n因此，在满足要求的前提下，我更喜欢符合Go语言哲学的方案。\n\nhttps://leetcode-cn.com/chai2010/\n\n## 辅助函数\n\n为了便于测试，构造了`Assert`和`Assertf`函数：\n\n```go\nfunc Assert(tb testing.TB, condition bool, a ...interface{}) {\n\ttb.Helper()\n\tif !condition {\n\t\tif msg := fmt.Sprint(a...); msg != \"\" {\n\t\t\ttb.Fatal(\"Assert failed: \" + msg)\n\t\t} else {\n\t\t\ttb.Fatal(\"Assert failed\")\n\t\t}\n\t}\n}\n\nfunc Assertf(tb testing.TB, condition bool, format string, a ...interface{}) {\n\ttb.Helper()\n\tif !condition {\n\t\tif msg := fmt.Sprintf(format, a...); msg != \"\" {\n\t\t\ttb.Fatal(\"Assert failed: \" + msg)\n\t\t} else {\n\t\t\ttb.Fatal(\"Assert failed\")\n\t\t}\n\t}\n}\n```\n\n在单元测试中可以这样使用：\n\n```go\nfunc TestFoo(*testing.T) {\n\tAssert(t, 1+1 == 2, \"some\", \"message\")\n}\nfunc TestBar(*testing.T) {\n\tAssertf(t, 1+1 == 2, \"%s, %s\", \"some\", \"message\")\n}\n```\n\n也可以在基准测试中使用：\n\n```go\nfunc BenchmarkHello(b *testing.B) {\n\tfor i := 0; i \u003c b.N; i++ {\n\t\tv := fmt.Sprintf(\"hello\")\n\t\tAssert(b, v == \"hello\")\n\t}\n}\n```\n\n## BUGS\n\nReport bugs to \u003cchaishushan@gmail.com\u003e.\n\nThanks!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchai2010%2Fleetcode-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchai2010%2Fleetcode-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchai2010%2Fleetcode-go/lists"}