forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: format go code with gofmt (doocs#1037)
- Loading branch information
Showing
292 changed files
with
3,087 additions
and
3,078 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ func replaceSpaces(S string, length int) string { | |
} | ||
} | ||
return string(b[j:]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,4 @@ func min(x, y, z int) int { | |
return y | ||
} | ||
return z | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ func compressString(S string) string { | |
return S | ||
} | ||
return builder.String() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ func rotate(matrix [][]int) { | |
matrix[j][n-i-1] = temp | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
func isFlipedString(s1 string, s2 string) bool { | ||
return len(s1) == len(s2) && strings.Contains(s1+s1, s2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ func removeDuplicateNodes(head *ListNode) *ListNode { | |
} | ||
} | ||
return head | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ func kthToLast(head *ListNode, k int) int { | |
fast = fast.Next | ||
} | ||
return slow.Val | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,4 @@ func reverse(head *ListNode) *ListNode { | |
head = temp | ||
} | ||
return prev | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,4 @@ func (s *SortedStack) Peek() int { | |
|
||
func (s *SortedStack) IsEmpty() bool { | ||
return len(s.data) == 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,4 @@ func listOfDepth(tree *TreeNode) []*ListNode { | |
ans = append(ans, head.Next) | ||
} | ||
return ans | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,4 @@ func abs(x int) int { | |
return -x | ||
} | ||
return x | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,4 @@ func check(node *TreeNode, lower, upper int) bool { | |
// node = node.Right | ||
// } | ||
// return true | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
func exchangeBits(num int) int { | ||
return ((num & 0x55555555) << 1) | (num&0xaaaaaaaa)>>1 | ||
func exchangeBits(num int) int { | ||
return ((num & 0x55555555) << 1) | (num&0xaaaaaaaa)>>1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
func subsets(nums []int) [][]int { | ||
var ans [][]int | ||
var dfs func(u int, t []int) | ||
dfs = func(u int, t []int) { | ||
if u == len(nums) { | ||
ans = append(ans, append([]int(nil), t...)) | ||
return | ||
} | ||
dfs(u+1, t) | ||
t = append(t, nums[u]) | ||
dfs(u+1, t) | ||
t = t[:len(t)-1] | ||
} | ||
var t []int | ||
dfs(0, t) | ||
return ans | ||
func subsets(nums []int) [][]int { | ||
var ans [][]int | ||
var dfs func(u int, t []int) | ||
dfs = func(u int, t []int) { | ||
if u == len(nums) { | ||
ans = append(ans, append([]int(nil), t...)) | ||
return | ||
} | ||
dfs(u+1, t) | ||
t = append(t, nums[u]) | ||
dfs(u+1, t) | ||
t = t[:len(t)-1] | ||
} | ||
var t []int | ||
dfs(0, t) | ||
return ans | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
func permutation(S string) []string { | ||
vis := make(map[byte]bool) | ||
var ans []string | ||
var t []byte | ||
var dfs func(u int, t []byte) | ||
dfs = func(u int, t []byte) { | ||
if u == len(S) { | ||
ans = append(ans, string(t)) | ||
return | ||
} | ||
for i := range S { | ||
if vis[S[i]] { | ||
continue | ||
} | ||
vis[S[i]] = true | ||
t = append(t, S[i]) | ||
dfs(u+1, t) | ||
vis[S[i]] = false | ||
t = t[:len(t)-1] | ||
} | ||
} | ||
dfs(0, t) | ||
return ans | ||
func permutation(S string) []string { | ||
vis := make(map[byte]bool) | ||
var ans []string | ||
var t []byte | ||
var dfs func(u int, t []byte) | ||
dfs = func(u int, t []byte) { | ||
if u == len(S) { | ||
ans = append(ans, string(t)) | ||
return | ||
} | ||
for i := range S { | ||
if vis[S[i]] { | ||
continue | ||
} | ||
vis[S[i]] = true | ||
t = append(t, S[i]) | ||
dfs(u+1, t) | ||
vis[S[i]] = false | ||
t = t[:len(t)-1] | ||
} | ||
} | ||
dfs(0, t) | ||
return ans | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
func findClosest(words []string, word1 string, word2 string) int { | ||
i, j, ans := 100000, -100000, 100000 | ||
for k, word := range words { | ||
if word == word1 { | ||
i = k | ||
} else if word == word2 { | ||
j = k | ||
} | ||
ans = min(ans, abs(i-j)) | ||
} | ||
return ans | ||
} | ||
|
||
func min(a, b int) int { | ||
if a < b { | ||
return a | ||
} | ||
return b | ||
} | ||
|
||
func abs(x int) int { | ||
if x < 0 { | ||
return -x | ||
} | ||
return x | ||
func findClosest(words []string, word1 string, word2 string) int { | ||
i, j, ans := 100000, -100000, 100000 | ||
for k, word := range words { | ||
if word == word1 { | ||
i = k | ||
} else if word == word2 { | ||
j = k | ||
} | ||
ans = min(ans, abs(i-j)) | ||
} | ||
return ans | ||
} | ||
|
||
func min(a, b int) int { | ||
if a < b { | ||
return a | ||
} | ||
return b | ||
} | ||
|
||
func abs(x int) int { | ||
if x < 0 { | ||
return -x | ||
} | ||
return x | ||
} |
Oops, something went wrong.