File tree Expand file tree Collapse file tree 3 files changed +88
-0
lines changed
lcof2/ๅๆ Offer II 018. ๆๆ็ๅๆ Expand file tree Collapse file tree 3 files changed +88
-0
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,56 @@ func isalnum(b byte) bool {
124
124
}
125
125
```
126
126
127
+ ### ** TypeScript**
128
+
129
+ ``` ts
130
+ function isPalindrome(s : string ): boolean {
131
+ const str = s .replace (/ [^ a-zA-Z0-9 ] / g , ' ' );
132
+ let l = 0 ;
133
+ let r = str .length - 1 ;
134
+ while (l < r ) {
135
+ if (str [l ].toLocaleLowerCase () !== str [r ].toLocaleLowerCase ()) {
136
+ return false ;
137
+ }
138
+ l ++ ;
139
+ r -- ;
140
+ }
141
+ return true ;
142
+ }
143
+ ```
144
+
145
+ ### ** Rust**
146
+
147
+ ไฝฟ็จ ` is_alphabetic() ` ไธ ` is_numeric() ` ่ฟๆปคๅญ็ฌฆ
148
+
149
+ ``` rust
150
+ impl Solution {
151
+ pub fn is_palindrome (s : String ) -> bool {
152
+ let ss : Vec <char > = s . chars (). collect ();
153
+ let mut l = 0 ;
154
+ let mut r = ss . len () - 1 ;
155
+ while l < r {
156
+ while l < r && ! (ss [l ]. is_alphabetic () || ss [l ]. is_numeric ()) {
157
+ l += 1 ;
158
+ }
159
+ while l < r && ! (ss [r ]. is_alphabetic () || ss [r ]. is_numeric ()) {
160
+ r -= 1 ;
161
+ }
162
+ if ss [l ]. to_ascii_lowercase () != ss [r ]. to_ascii_lowercase () {
163
+ return false ;
164
+ }
165
+ // ้ฒๆญข usize ็ ด็
166
+ if r == 0 {
167
+ return true ;
168
+ }
169
+ l += 1 ;
170
+ r -= 1 ;
171
+ }
172
+ true
173
+ }
174
+ }
175
+ ```
176
+
127
177
### ** ...**
128
178
129
179
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn is_palindrome ( s : String ) -> bool {
3
+ let ss: Vec < char > = s. chars ( ) . collect ( ) ;
4
+ let mut l = 0 ;
5
+ let mut r = ss. len ( ) - 1 ;
6
+ while l < r {
7
+ while l < r && !( ss[ l] . is_alphabetic ( ) || ss[ l] . is_numeric ( ) ) {
8
+ l += 1 ;
9
+ }
10
+ while l < r && !( ss[ r] . is_alphabetic ( ) || ss[ r] . is_numeric ( ) ) {
11
+ r -= 1 ;
12
+ }
13
+ if ss[ l] . to_ascii_lowercase ( ) != ss[ r] . to_ascii_lowercase ( ) {
14
+ return false ;
15
+ }
16
+ // ้ฒๆญข usize ็ ด็
17
+ if r == 0 {
18
+ return true ;
19
+ }
20
+ l += 1 ;
21
+ r -= 1 ;
22
+ }
23
+ true
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ function isPalindrome ( s : string ) : boolean {
2
+ const str = s . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, '' ) ;
3
+ let l = 0 ;
4
+ let r = str . length - 1 ;
5
+ while ( l < r ) {
6
+ if ( str [ l ] . toLocaleLowerCase ( ) !== str [ r ] . toLocaleLowerCase ( ) ) {
7
+ return false ;
8
+ }
9
+ l ++ ;
10
+ r -- ;
11
+ }
12
+ return true ;
13
+ }
You canโt perform that action at this time.
0 commit comments