Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit47ebcd4

Browse files
committed
modify content
1 parent35f56aa commit47ebcd4

File tree

53 files changed

+1065
-413
lines changed

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

+1065
-413
lines changed

‎1. Two Sum.gorenamed to‎1. [E]Two Sum.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package main
22

3+
/**
4+
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
5+
You may assume that each input would have exactly one solution, and you may not use the same element twice.
6+
Example:
7+
Given nums = [2, 7, 11, 15], target = 9,
8+
Because nums[0] + nums[1] = 2 + 7 = 9,
9+
return [0, 1].
10+
*/
11+
312
/**
413
用hash保存另一个数的值,遍历的同时判断是否存在
514
*/

‎11. Container With Most Water.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎11.[M] Container With Most Water.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
/**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.
4+
5+
Note: You may not slant the container and n is at least 2.
6+
7+
The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
8+
9+
Example:
10+
11+
Input: [1,8,6,2,5,4,8,3,7]
12+
Output: 49
13+
14+
*/
15+
funcmaxArea(height []int)int {
16+
left,right:=0,len(height)-1
17+
maxArea:=0
18+
forleft<right {
19+
maxArea=max(maxArea,min(height[left],height[right])*(right-left))
20+
ifheight[left]<height[right] {
21+
left++
22+
}else {
23+
right--
24+
}
25+
}
26+
returnmaxArea
27+
}
28+
29+
funcmax(x,yint)int {
30+
ifx>y {
31+
returnx
32+
}
33+
returny
34+
}
35+
funcmin(x,yint)int {
36+
ifx>y {
37+
returny
38+
}
39+
returnx
40+
}

‎14. Longest Common Prefix.gorenamed to‎14.[E] Longest Common Prefix.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ package main
22

33
import"math"
44

5+
/**
6+
Write a function to find the longest common prefix string amongst an array of strings.
7+
8+
If there is no common prefix, return an empty string "".
9+
10+
Example 1:
11+
12+
Input: ["flower","flow","flight"]
13+
Output: "fl"
14+
Example 2:
15+
16+
Input: ["dog","racecar","car"]
17+
Output: ""
18+
Explanation: There is no common prefix among the input strings.
19+
20+
*/
521
funclongestCommonPrefix(strs []string)string {
622
iflen(strs)==0 {
723
return""

‎15. 3Sum.gorenamed to‎15.[M]3Sum.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@ package main
22

33
import"sort"
44

5+
/**
6+
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.
7+
8+
Note:
9+
10+
The solution set must not contain duplicate triplets.
11+
12+
Example:
13+
14+
Given array nums = [-1, 0, 1, 2, -1, -4],
15+
16+
A solution set is:
17+
[
18+
[-1, 0, 1],
19+
[-1, -1, 2]
20+
]
21+
*/
522
functhreeSum(nums []int) [][]int {
623
//先排序
724
sort.Ints(nums)

‎16. 3Sum Closest.gorenamed to‎16.[M]3Sum Closest.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ import (
55
"sort"
66
)
77

8+
/**
9+
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.
10+
11+
Example:
12+
13+
Given array nums = [-1, 2, 1, -4], and target = 1.
14+
15+
The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
16+
17+
*/
18+
819
functhreeSumClosest(nums []int,targetint)int {
920
dist:=math.MaxInt32
1021
ret:=0

‎17. Letter Combinations of a Phone Number.gorenamed to‎17.[M]Letter Combinations of a Phone Number.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
package main
22

3+
/**
4+
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
5+
6+
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
7+
8+
9+
10+
Example:
11+
12+
Input: "23"
13+
Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
14+
*/
315
/*
416
回溯算法
517
*/

‎18. 4Sum.gorenamed to‎18.[M]4Sum.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ import (
44
"sort"
55
)
66

7+
/**
8+
Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.
9+
10+
Note:
11+
12+
The solution set must not contain duplicate quadruplets.
13+
14+
Example:
15+
16+
Given array nums = [1, 0, -1, 0, -2, 2], and target = 0.
17+
18+
A solution set is:
19+
[
20+
[-1, 0, 0, 1],
21+
[-2, -1, 1, 2],
22+
[-2, 0, 0, 2]
23+
]
24+
*/
725
/**
826
四重循环加上剪枝AC
927
三重循环加上左右指针居然MLE

‎19. Remove Nth Node From End of List.gorenamed to‎19.[M]Remove Nth Node From End of List.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
package main
22

3+
/**
4+
Given a linked list, remove the n-th node from the end of list and return its head.
5+
6+
Example:
7+
8+
Given linked list: 1->2->3->4->5, and n = 2.
9+
10+
After removing the second node from the end, the linked list becomes 1->2->3->5.
11+
Note:
12+
13+
Given n will always be valid.
14+
*/
15+
16+
/**
17+
* 快慢指针,快指针先前进n步,然后两个指针一起前进,当快指针走到末尾的时候,慢指针所在的位置,就是目标位置
18+
*/
319
typeListNodestruct {
420
Valint
521
Next*ListNode
622
}
723

8-
/**
9-
* 快慢指针,快指针先前进n步,然后两个指针一起前进,当快指针走到末尾的时候,慢指针所在的位置,就是目标位置
10-
*/
1124
funcremoveNthFromEnd(head*ListNode,nint)*ListNode {
1225
cur:=head
1326
last:=head

‎2. Add Two Numbers.gorenamed to‎2. [M]Add Two Numbers.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
package main
22

3-
typeListNodestruct {
4-
Valint
5-
Next*ListNode
6-
}
3+
/**
4+
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
5+
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
6+
Example:
7+
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
8+
Output: 7 -> 0 -> 8
9+
Explanation: 342 + 465 = 807.
10+
*/
711

812
/**
913
注意的问题:
1014
1.进位
1115
2.两个list的长度不一定相等
1216
*/
17+
18+
typeListNodestruct {
19+
Valint
20+
Next*ListNode
21+
}
22+
1323
funcaddTwoNumbers(l1*ListNode,l2*ListNode)*ListNode {
1424
result:=&ListNode{0,nil}
1525
cursor:=result

‎20. Valid Parentheses.gorenamed to‎20. [E]Valid Parentheses.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
package main
22

3+
/**
4+
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
5+
6+
An input string is valid if:
7+
8+
Open brackets must be closed by the same type of brackets.
9+
Open brackets must be closed in the correct order.
10+
Note that an empty string is also considered valid.
11+
12+
Example 1:
13+
14+
Input: "()"
15+
Output: true
16+
Example 2:
17+
18+
Input: "()[]{}"
19+
Output: true
20+
Example 3:
21+
22+
Input: "(]"
23+
Output: false
24+
Example 4:
25+
26+
Input: "([)]"
27+
Output: false
28+
Example 5:
29+
30+
Input: "{[]}"
31+
Output: true
32+
*/
333
/**
434
用一个slice模拟stack
535
遍历字符串,遇到左括号入栈,遇到右括号出战并判断

‎21. Merge Two Sorted Lists.gorenamed to‎21. [E]Merge Two Sorted Lists.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
package main
22

3-
typeListNodestruct {
4-
Valint
5-
Next*ListNode
6-
}
3+
/**
4+
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
5+
6+
Example:
7+
8+
Input: 1->2->4, 1->3->4
9+
Output: 1->1->2->3->4->4
10+
*/
711

812
/**
913
递归操作
1014
当某一个为空的时候,退出
1115
*/
16+
typeListNodestruct {
17+
Valint
18+
Next*ListNode
19+
}
20+
1221
funcmergeTwoLists(l1*ListNode,l2*ListNode)*ListNode {
1322
ifl1==nil {
1423
returnl2
File renamed without changes.

‎23. Merge k Sorted Lists.gorenamed to‎23. [H]Merge k Sorted Lists.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
package main
22

3-
typeListNodestruct {
4-
Valint
5-
Next*ListNode
6-
}
3+
/**
4+
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
5+
6+
Example:
7+
8+
Input:
9+
[
10+
1->4->5,
11+
1->3->4,
12+
2->6
13+
]
14+
Output: 1->1->2->3->4->4->5->6
15+
*/
716

817
/**
918
分治的方法,不停的两两merge
1019
其中merge两个list的方法,就是#21
1120
*/
21+
typeListNodestruct {
22+
Valint
23+
Next*ListNode
24+
}
1225

1326
funcmergeKLists(lists []*ListNode)*ListNode {
1427
iflen(lists)==0 {

‎26. Remove Duplicates from Sorted Array.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp