Skip to content

Commit 52b09c0

Browse files
author
easyone
committed
Feat: Add solution of valid-palindrome
1 parent 1a00ff9 commit 52b09c0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

contains-duplicate/easyone-jwlee.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ func containsDuplicate(nums []int) bool {
77
m[num] = num
88
}
99
return false
10-
}
10+
}

valid-palindrome/easyone-jwlee.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
func isPalindrome(s string) bool {
2+
s = strings.ToLower(s)
3+
validStr := ""
4+
for _, str := range s {
5+
if ('a' > str || 'z' < str) && ('0' > str || '9' < str) {
6+
continue
7+
}
8+
validStr += string(str)
9+
}
10+
if len(validStr) <= 1 {
11+
return true
12+
}
13+
l := len(validStr)
14+
for i := 0; i < l/2; i++ {
15+
if validStr[i] != validStr[l-1-i] {
16+
return false
17+
}
18+
}
19+
return true
20+
}

0 commit comments

Comments
 (0)