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 55// O(n) space complexity
66func isPalindrome (s string ) bool {
77 regex , _ := regexp .Compile ("[a-zA-Z0-9]" )
8+
9+ lowerCaseString := strings .ToLower (s )
810 reverseAndFilteredString := ""
911 filteredString := ""
1012
11- for _ , char := range s {
13+ for _ , char := range lowerCaseString {
1214 if regex .MatchString (string (char )) {
13- c := strings .ToLower (string (char ))
1415 reverseAndFilteredString = c + reverseAndFilteredString
1516 filteredString += c
1617 }
@@ -22,12 +23,12 @@ func isPalindrome(s string) bool {
2223// O(n) time complexity
2324// O(n) space complexity
2425func isPalindrome2 (s string ) bool {
26+ lowerCaseString := strings .ToLower (s )
2527 reverseAndFilteredString := ""
2628 filteredString := ""
2729
28- for _ , char := range s {
30+ for _ , char := range lowerCaseString {
2931 if unicode .IsLetter (char ) || unicode .IsDigit (char ) {
30- c := strings .ToLower (string (char ))
3132 reverseAndFilteredString = c + reverseAndFilteredString
3233 filteredString += c
3334 }
You can’t perform that action at this time.
0 commit comments