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

Commit 49e5c09

Browse files
go: 14, 88, 125
1 parent ce9ebd6 commit 49e5c09

File tree

9 files changed

+204
-5
lines changed

9 files changed

+204
-5
lines changed

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ You can also ask for problem solving ideas and discuss in GitHub issues directly
882882
|7|[Reverse Integer](https://leetcode.com/problems/reverse-integer/description/)|[Java](../master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/strings/_7.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/7.go) |Easy| Strings
883883
|8|[String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/strings/_8.java) & Python |Medium| Strings
884884
|13|[Roman to Integer](https://leetcode.com/problems/roman-to-integer/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/math/_13.java) & Python |Easy| Math
885-
|14|[Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_14.java) & Python|Easy| Strings
885+
|14|[Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_14.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/14.go)|Easy| Strings
886886
|19|[Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/linked_list/_19.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/19.go)|Medium| Linked List
887887
|20|[Valid Parentheses](https://leetcode.com/problems/valid-parentheses/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/queue_stack/_20.java) & Python|Easy| Others
888888
|21|[Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/linked_list/_21.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/21.go)|Easy| Linked List
@@ -894,7 +894,7 @@ You can also ask for problem solving ideas and discuss in GitHub issues directly
894894
|53|[Maximum Subarray](https://leetcode.com/problems/maximum-subarray/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/dynamic_programming/_53.java) & [Python](https://github.com/guobinhit/myleetcode/blob/master/codes/python/leetcodes/src/main/python/com/hit/basmath/interview/top_interview_questions/easy_collection/dynamic_programming/_53.py) |Easy| Dynamic Programming
895895
|66|[Plus One](https://leetcode.com/problems/plus-one/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_66.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/66.go)|Easy| Array
896896
|70|[Climbing Stairs](https://leetcode.com/problems/climbing-stairs/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_70.java) & Python| Easy| Dynamic Programming
897-
|88|[Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/sorting_and_searching/_88.java) & Python |Easy| Sorting and Searching
897+
|88|[Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/sorting_and_searching/_88.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/88.go) |Easy| Sorting and Searching
898898
|98|[Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/binary_search_tree/_98.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/98.go) |Medium| Trees
899899
|101|[Symmetric Tree](https://leetcode.com/problems/symmetric-tree/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/binary_tree/_101.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/101.go) |Easy| Trees
900900
|102|[Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/binary_tree/_102.java) & Python |Medium| Trees
@@ -903,7 +903,7 @@ You can also ask for problem solving ideas and discuss in GitHub issues directly
903903
|118|[Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_118.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/7.go)| Easy| Others
904904
|121|[Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/dynamic_programming/_121.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/121.go) |Easy| Dynamic Programming
905905
|122|[Best Time to Buy and Sell Stock II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/array/_122.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/122.go)|Easy| Array
906-
|125|[Valid Palindrome](https://leetcode.com/problems/valid-palindrome/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/strings/_125.java) & Python |Easy| Strings
906+
|125|[Valid Palindrome](https://leetcode.com/problems/valid-palindrome/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/strings/_125.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/125.go) |Easy| Strings
907907
|136|[Single Number](https://leetcode.com/problems/single-number/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/hash_table/_136.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/136.go) |Easy| Array
908908
|141|[Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/linked_list/_141.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/141.go)|Easy| Linked List
909909
|155|[Min Stack](https://leetcode.com/problems/min-stack/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/queue_stack/_155.java) & Python|Easy| Design

‎codes/go/leetcodes/go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ module github.com/guobinhit/myleetcodes
33
go 1.15
44

55
require (
6-
github.com/guobinhit/sylph v1.4.0
6+
github.com/guobinhit/sylph v1.5.2
77
github.com/stretchr/testify v1.7.0
88
)

‎codes/go/leetcodes/go.sum‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ github.com/guobinhit/sylph v1.3.3 h1:EUflyQ3MvrufyrGRC5sSo5ND94eeeASHw22zBMpUyrM
33
github.com/guobinhit/sylph v1.3.3/go.mod h1:nvTaI9mV07YK//oYVLGG9MGqX7oy5xid/DDxp1eT3YE=
44
github.com/guobinhit/sylph v1.4.0 h1:UDnKH3hp3ejHgnSXFyRA6DUSuTRP0ya4KNbGF5oDhPk=
55
github.com/guobinhit/sylph v1.4.0/go.mod h1:nvTaI9mV07YK//oYVLGG9MGqX7oy5xid/DDxp1eT3YE=
6+
github.com/guobinhit/sylph v1.5.2 h1:wcBjljwXyj2Jr8EBrNVtKTVeZEXrxQtSFYMxHf7EoCc=
7+
github.com/guobinhit/sylph v1.5.2/go.mod h1:nvTaI9mV07YK//oYVLGG9MGqX7oy5xid/DDxp1eT3YE=
68
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
79
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
810
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=

‎codes/go/leetcodes/interview/easy_collection/118_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package easy_collection
22

33
import (
4-
"github.com/guobinhit/sylph/common/utils"
4+
"github.com/guobinhit/sylph/utils"
55
"reflect"
66
"testing"
77
)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package easy_collection
2+
3+
import "strings"
4+
5+
/**
6+
* 125. Valid Palindrome
7+
* <p>
8+
* Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
9+
* <p>
10+
* Note: For the purpose of this problem, we define empty string as valid palindrome.
11+
* <p>
12+
* Example 1:
13+
* <p>
14+
* Input: "A man, a plan, a canal: Panama"
15+
* Output: true
16+
* <p>
17+
* Example 2:
18+
* <p>
19+
* Input: "race a car"
20+
* Output: false
21+
*/
22+
23+
func isPalindrome125(s string) bool {
24+
var sb strings.Builder
25+
s = strings.ToLower(s)
26+
for _, ch := range s {
27+
if (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') {
28+
sb.WriteString(string(ch))
29+
}
30+
}
31+
i := 0
32+
j := len(sb.String()) - 1
33+
s = sb.String()
34+
for i <= j {
35+
if s[i] != s[j] {
36+
return false
37+
}
38+
i += 1
39+
j -= 1
40+
}
41+
return true
42+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package easy_collection
2+
3+
import "testing"
4+
5+
func Test_isPalindrome125(t *testing.T) {
6+
type args struct {
7+
s string
8+
}
9+
tests := []struct {
10+
name string
11+
args args
12+
want bool
13+
}{
14+
{
15+
name: "isPalindrome125 true",
16+
args: args{s: "A man, a plan, a canal: Panama"},
17+
want: true,
18+
},
19+
{
20+
name: "isPalindrome125 false",
21+
args: args{s: ".,"},
22+
want: true,
23+
},
24+
}
25+
for _, tt := range tests {
26+
t.Run(tt.name, func(t *testing.T) {
27+
if got := isPalindrome125(tt.args.s); got != tt.want {
28+
t.Errorf("isPalindrome125() = %v, want %v", got, tt.want)
29+
}
30+
})
31+
}
32+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package easy_collection
2+
3+
import "strings"
4+
5+
/**
6+
* 14. Longest Common Prefix
7+
* <p>
8+
* Write a function to find the longest common prefix string amongst an array of strings.
9+
* <p>
10+
* If there is no common prefix, return an empty string "".
11+
* <p>
12+
* Example 1:
13+
* <p>
14+
* Input: ["flower","flow","flight"]
15+
* Output: "fl"
16+
* <p>
17+
* Example 2:
18+
* <p>
19+
* Input: ["dog","racecar","car"]
20+
* Output: ""
21+
* <p>
22+
* Explanation: There is no common prefix among the input strings.
23+
* <p>
24+
* Note:
25+
* <p>
26+
* All given inputs are in lowercase letters a-z.
27+
*/
28+
29+
func longestCommonPrefix(strs []string) string {
30+
if len(strs) == 0 {
31+
return ""
32+
}
33+
aimStr := strs[0]
34+
index := 1
35+
for index < len(strs) {
36+
for !strings.HasPrefix(strs[index], aimStr) {
37+
aimStr = aimStr[0 : len(aimStr)-1]
38+
}
39+
if len(aimStr) == 0 {
40+
return ""
41+
}
42+
index++
43+
}
44+
return aimStr
45+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package easy_collection
2+
3+
/**
4+
* 88. Merge Sorted Array
5+
* <p>
6+
* Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
7+
* <p>
8+
* Note:
9+
* <p>
10+
* The number of elements initialized in nums1 and nums2 are m and n respectively.
11+
* You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.
12+
* <p>
13+
* Example:
14+
* <p>
15+
* Input:
16+
* <p>
17+
* nums1 = [1,2,3,0,0,0], m = 3
18+
* nums2 = [2,5,6], n = 3
19+
* <p>
20+
* Output: [1,2,2,3,5,6]
21+
*/
22+
23+
func merge(nums1 []int, m int, nums2 []int, n int) {
24+
i := m - 1
25+
j := n - 1
26+
k := m + n - 1
27+
for i > -1 && j > -1 {
28+
if nums1[i] > nums2[j] {
29+
nums1[k] = nums1[i]
30+
i--
31+
} else {
32+
nums1[k] = nums2[j]
33+
j--
34+
}
35+
k--
36+
}
37+
for j > -1 {
38+
nums1[k] = nums2[j]
39+
k--
40+
j--
41+
}
42+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package easy_collection
2+
3+
import (
4+
"fmt"
5+
"github.com/guobinhit/sylph/utils"
6+
"testing"
7+
)
8+
9+
func Test_merge(t *testing.T) {
10+
type args struct {
11+
nums1 []int
12+
m int
13+
nums2 []int
14+
n int
15+
}
16+
tests := []struct {
17+
name string
18+
args args
19+
}{
20+
{
21+
name: "merge",
22+
args: args{
23+
nums1: []int{4, 5, 6, 0, 0, 0},
24+
m: 3,
25+
nums2: []int{1, 2, 3},
26+
n: 3,
27+
},
28+
},
29+
}
30+
for _, tt := range tests {
31+
t.Run(tt.name, func(t *testing.T) {
32+
merge(tt.args.nums1, tt.args.m, tt.args.nums2, tt.args.n)
33+
fmt.Println(utils.Json(tt.args.nums1))
34+
})
35+
}
36+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /