Skip to content

Commit

Permalink
style: format go code with gofmt (doocs#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme authored Jun 15, 2023
1 parent f8e49aa commit cf29a78
Show file tree
Hide file tree
Showing 292 changed files with 3,087 additions and 3,078 deletions.
2 changes: 1 addition & 1 deletion lcci/01.03.String to URL/Solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ func replaceSpaces(S string, length int) string {
}
}
return string(b[j:])
}
}
2 changes: 1 addition & 1 deletion lcci/01.05.One Away/Solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ func min(x, y, z int) int {
return y
}
return z
}
}
2 changes: 1 addition & 1 deletion lcci/01.06.Compress String/Solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ func compressString(S string) string {
return S
}
return builder.String()
}
}
2 changes: 1 addition & 1 deletion lcci/01.07.Rotate Matrix/Solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ func rotate(matrix [][]int) {
matrix[j][n-i-1] = temp
}
}
}
}
2 changes: 1 addition & 1 deletion lcci/01.09.String Rotation/Solution.go
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)
}
}
2 changes: 1 addition & 1 deletion lcci/02.01.Remove Duplicate Node/Solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ func removeDuplicateNodes(head *ListNode) *ListNode {
}
}
return head
}
}
2 changes: 1 addition & 1 deletion lcci/02.02.Kth Node From End of List/Solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ func kthToLast(head *ListNode, k int) int {
fast = fast.Next
}
return slow.Val
}
}
2 changes: 1 addition & 1 deletion lcci/02.06.Palindrome Linked List/Solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ func reverse(head *ListNode) *ListNode {
head = temp
}
return prev
}
}
30 changes: 15 additions & 15 deletions lcci/02.07.Intersection of Two Linked Lists/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,21 @@ var getIntersectionNode = function (headA, headB) {
* Next *ListNode
* }
*/
func getIntersectionNode(headA, headB *ListNode) *ListNode {
cur1, cur2 := headA, headB
for cur1 != cur2 {
if cur1 == nil {
cur1 = headB
} else {
cur1 = cur1.Next
}
if cur2 == nil {
cur2 = headA
} else {
cur2 = cur2.Next
}
}
return cur1
func getIntersectionNode(headA, headB *ListNode) *ListNode {
cur1, cur2 := headA, headB
for cur1 != cur2 {
if cur1 == nil {
cur1 = headB
} else {
cur1 = cur1.Next
}
if cur2 == nil {
cur2 = headA
} else {
cur2 = cur2.Next
}
}
return cur1
}
```

Expand Down
30 changes: 15 additions & 15 deletions lcci/02.07.Intersection of Two Linked Lists/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,21 @@ var getIntersectionNode = function (headA, headB) {
* Next *ListNode
* }
*/
func getIntersectionNode(headA, headB *ListNode) *ListNode {
cur1, cur2 := headA, headB
for cur1 != cur2 {
if cur1 == nil {
cur1 = headB
} else {
cur1 = cur1.Next
}
if cur2 == nil {
cur2 = headA
} else {
cur2 = cur2.Next
}
}
return cur1
func getIntersectionNode(headA, headB *ListNode) *ListNode {
cur1, cur2 := headA, headB
for cur1 != cur2 {
if cur1 == nil {
cur1 = headB
} else {
cur1 = cur1.Next
}
if cur2 == nil {
cur2 = headA
} else {
cur2 = cur2.Next
}
}
return cur1
}
```

Expand Down
30 changes: 15 additions & 15 deletions lcci/02.07.Intersection of Two Linked Lists/Solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
* Next *ListNode
* }
*/
func getIntersectionNode(headA, headB *ListNode) *ListNode {
cur1, cur2 := headA, headB
for cur1 != cur2 {
if cur1 == nil {
cur1 = headB
} else {
cur1 = cur1.Next
}
if cur2 == nil {
cur2 = headA
} else {
cur2 = cur2.Next
}
}
return cur1
func getIntersectionNode(headA, headB *ListNode) *ListNode {
cur1, cur2 := headA, headB
for cur1 != cur2 {
if cur1 == nil {
cur1 = headB
} else {
cur1 = cur1.Next
}
if cur2 == nil {
cur2 = headA
} else {
cur2 = cur2.Next
}
}
return cur1
}
2 changes: 1 addition & 1 deletion lcci/03.01.Three in One/Solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ func (this *TripleInOne) IsEmpty(stackNum int) bool {
* param_2 := obj.Pop(stackNum);
* param_3 := obj.Peek(stackNum);
* param_4 := obj.IsEmpty(stackNum);
*/
*/
2 changes: 1 addition & 1 deletion lcci/03.04.Implement Queue using Stacks/Solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ func (this *MyQueue) transfer() {
* param_2 := obj.Pop();
* param_3 := obj.Peek();
* param_4 := obj.Empty();
*/
*/
2 changes: 1 addition & 1 deletion lcci/03.05.Sort of Stacks/Solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ func (s *SortedStack) Peek() int {

func (s *SortedStack) IsEmpty() bool {
return len(s.data) == 0
}
}
2 changes: 1 addition & 1 deletion lcci/04.03.List of Depth/Solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ func listOfDepth(tree *TreeNode) []*ListNode {
ans = append(ans, head.Next)
}
return ans
}
}
2 changes: 1 addition & 1 deletion lcci/04.04.Check Balance/Solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ func abs(x int) int {
return -x
}
return x
}
}
2 changes: 1 addition & 1 deletion lcci/04.05.Legal Binary Search Tree/Solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ func check(node *TreeNode, lower, upper int) bool {
// node = node.Right
// }
// return true
// }
// }
4 changes: 2 additions & 2 deletions lcci/05.07.Exchange/Solution.go
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
}
32 changes: 16 additions & 16 deletions lcci/08.04.Power Set/Solution.go
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
}
46 changes: 23 additions & 23 deletions lcci/08.07.Permutation I/Solution.go
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
}
50 changes: 25 additions & 25 deletions lcci/17.11.Find Closest/Solution.go
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
}
Loading

0 comments on commit cf29a78

Please sign in to comment.