File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 5
5
// O(n) space complexity
6
6
func isPalindrome (s string ) bool {
7
7
regex , _ := regexp .Compile ("[a-zA-Z0-9]" )
8
+
9
+ lowerCaseString := strings .ToLower (s )
8
10
reverseAndFilteredString := ""
9
11
filteredString := ""
10
12
11
- for _ , char := range s {
13
+ for _ , char := range lowerCaseString {
12
14
if regex .MatchString (string (char )) {
13
- c := strings .ToLower (string (char ))
14
15
reverseAndFilteredString = c + reverseAndFilteredString
15
16
filteredString += c
16
17
}
@@ -22,12 +23,12 @@ func isPalindrome(s string) bool {
22
23
// O(n) time complexity
23
24
// O(n) space complexity
24
25
func isPalindrome2 (s string ) bool {
26
+ lowerCaseString := strings .ToLower (s )
25
27
reverseAndFilteredString := ""
26
28
filteredString := ""
27
29
28
- for _ , char := range s {
30
+ for _ , char := range lowerCaseString {
29
31
if unicode .IsLetter (char ) || unicode .IsDigit (char ) {
30
- c := strings .ToLower (string (char ))
31
32
reverseAndFilteredString = c + reverseAndFilteredString
32
33
filteredString += c
33
34
}
You can’t perform that action at this time.
0 commit comments