Skip to content

Commit f463e7b

Browse files
committed
golang
1 parent 129aad9 commit f463e7b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+440
-2601
lines changed

.github/workflows/badge.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: badge
4+
5+
on:
6+
push:
7+
branches:
8+
- golang
9+
workflow_dispatch:
10+
11+
jobs:
12+
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- uses: shuzijun/[email protected]
20+
with:
21+
STATISTICS_DIRECTORY: .idea/leetcode-pro/
22+
LEETCODE_SITE: leetcode.cn
23+

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
2424

25-
src/main/java/com/shuzijun/leetcode/editor/cn/doc/solution/*.*
26-
src/main/java/com/shuzijun/leetcode/editor/cn/doc/submission/*.*
25+
.idea
26+
src/leetcode/editor/cn/doc/*.*
27+
src/leetcode/editor/cn/doc/*/*.*

.idea/leetcode-pro/editor.xml

Lines changed: 28 additions & 106 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
11
# leetcode-question
2-
[leetcode-editor](https://github.com/shuzijun/leetcode-editor) custom code demo
3-
This branch is a private record branch. For configuration examples, please refer to master.
4-
## leetcode-editor config
5-
CodeFileName:
6-
```java
7-
Q${question.frontendQuestionId}$!velocityTool.camelCaseName(${question.titleSlug})
8-
```
9-
CodeTemplate:
10-
```java
11-
package com.shuzijun.leetcode.editor.cn;
12-
${question.content}
13-
14-
public class Q${question.frontendQuestionId}$!velocityTool.camelCaseName(${question.titleSlug}){
15-
public static void main(String[] args) {
16-
Solution solution = new Q${question.frontendQuestionId}$!velocityTool.camelCaseName(${question.titleSlug})().new Solution();
17-
}
18-
${question.code}
19-
}
20-
```
21-
TemplateConstant:
22-
```
23-
${question.title} question title ex:Two Sum
24-
${question.titleSlug} question title slug ex:two-sum
25-
${question.frontendQuestionId} question serial number
26-
${question.content} question content
27-
${question.code} question code
28-
$!velocityTool.camelCaseName(str) transform str camel case
29-
```
2+
3+
[leetcode-editor](https://github.com/shuzijun/leetcode-editor) custom code demo
4+
5+
## Progress
6+
7+
<!--START_SECTION_FLAG-->
8+
9+
![Progress](https://img.shields.io/static/v1?logo=leetcode&label=Progress&message=47%2F2647&color=brightgreen) ![Easy](https://img.shields.io/static/v1?logo=leetcode&label=Easy&message=58&color=5CB85C) ![Medium](https://img.shields.io/static/v1?logo=leetcode&label=Medium&message=106&color=F0AD4E) ![Hard](https://img.shields.io/static/v1?logo=leetcode&label=Hard&message=12&color=D9534F) <!--END_SECTION_FLAG-->
10+
11+
## leetcode-editor config
12+
13+
CodeFileName:
14+
15+
```java
16+
Q${question.frontendQuestionId}$!velocityTool.camelCaseName(${question.titleSlug})_test
17+
```
18+
19+
CodeTemplate:
20+
21+
```go
22+
package main
23+
24+
import "testing"
25+
26+
${q.content}
27+
28+
func Test$!vt.camelCaseName(${q.codeMetaData.name})(t *testing.T) {
29+
30+
}
31+
32+
${q.code}
33+
```
34+
35+
TemplateConstant:
36+
37+
```
38+
${question.title} question title ex:Two Sum
39+
${question.titleSlug} question title slug ex:two-sum
40+
${question.frontendQuestionId} question serial number
41+
${question.content} question content
42+
${question.code} question code
43+
$!velocityTool.camelCaseName(str) transform str camel case
44+
```

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module github.com/shuzijun/leetcode-question
2+
3+
go 1.18
4+

pom.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
)
6+
7+
/**
8+
<p>给定一个整数数组 <code>nums</code>&nbsp;和一个整数目标值 <code>target</code>,请你在该数组中找出 <strong>和为目标值 </strong><em><code>target</code></em>&nbsp; 的那&nbsp;<strong>两个</strong>&nbsp;整数,并返回它们的数组下标。</p>
9+
10+
<p>你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。</p>
11+
12+
<p>你可以按任意顺序返回答案。</p>
13+
14+
<p>&nbsp;</p>
15+
16+
<p><strong>示例 1:</strong></p>
17+
18+
<pre>
19+
<strong>输入:</strong>nums = [2,7,11,15], target = 9
20+
<strong>输出:</strong>[0,1]
21+
<strong>解释:</strong>因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。
22+
</pre>
23+
24+
<p><strong>示例 2:</strong></p>
25+
26+
<pre>
27+
<strong>输入:</strong>nums = [3,2,4], target = 6
28+
<strong>输出:</strong>[1,2]
29+
</pre>
30+
31+
<p><strong>示例 3:</strong></p>
32+
33+
<pre>
34+
<strong>输入:</strong>nums = [3,3], target = 6
35+
<strong>输出:</strong>[0,1]
36+
</pre>
37+
38+
<p>&nbsp;</p>
39+
40+
<p><strong>提示:</strong></p>
41+
42+
<ul>
43+
<li><code>2 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
44+
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
45+
<li><code>-10<sup>9</sup> &lt;= target &lt;= 10<sup>9</sup></code></li>
46+
<li><strong>只会存在一个有效答案</strong></li>
47+
</ul>
48+
49+
<p><strong>进阶:</strong>你可以想出一个时间复杂度小于 <code>O(n<sup>2</sup>)</code> 的算法吗?</p>
50+
51+
<div><details><summary>Related Topics</summary><div><li>数组</li><li>哈希表</li></div></details></div>
52+
<div><li>👍 15503</li><li>👎 0</li></div>
53+
*/
54+
55+
func TestTwoSum(t *testing.T) {
56+
t.Log(twoSum([]int{2, 7, 11, 15}, 9))
57+
}
58+
59+
//leetcode submit region begin(Prohibit modification and deletion)
60+
func twoSum(nums []int, target int) []int {
61+
hashTable := map[int]int{}
62+
for i, x := range nums {
63+
if p, ok := hashTable[target-x]; ok {
64+
return []int{p, i}
65+
}
66+
hashTable[x] = i
67+
}
68+
return nil
69+
}
70+
71+
//leetcode submit region end(Prohibit modification and deletion)

0 commit comments

Comments
 (0)