File tree Expand file tree Collapse file tree 2 files changed +83
-0
lines changed Expand file tree Collapse file tree 2 files changed +83
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ bool isPalindrome(string s) {
4
+ int i=0;
5
+ int j=s.length()-1;
6
+
7
+ if(s.length() == 1)
8
+ return true;
9
+
10
+ while(i<j)
11
+ {
12
+ if(!isAlp(s[ i] ))
13
+ {
14
+ i++;
15
+ }
16
+ else if(!isAlp(s[ j] ))
17
+ {
18
+ j--;
19
+ }
20
+ else if(s[ i] !=s[ j] )
21
+ return false;
22
+ else
23
+ {
24
+ i++;
25
+ j--;
26
+ }
27
+ }
28
+
29
+ return true;
30
+ }
31
+
32
+ bool isAlp(char &ch)
33
+ {
34
+ if(ch >= 'A' && ch <= 'Z')
35
+ {
36
+ ch += 32;
37
+ return true;
38
+ }
39
+
40
+ if(ch >= 'a' && ch <= 'z')
41
+ return true;
42
+
43
+ if(ch >= '0' && ch <= '9')
44
+ return true;
45
+
46
+ return false;
47
+ }
48
+ };
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ void reverseWords(string &s) {
4
+
5
+ int size = s.length();
6
+ stack<string > sta;
7
+
8
+ int begin = 0;
9
+ int cur = begin;
10
+ while(cur < size)
11
+ {
12
+ while(cur<size && s[ cur] ==' ')
13
+ cur++;
14
+
15
+ s.erase(begin, cur-begin);
16
+ begin = 0;
17
+ cur = 0;
18
+ size = s.length();
19
+ while(cur<size && s[ cur] !=' ')
20
+ cur++;
21
+ string tmp = s.substr(begin, cur-begin);
22
+ if(tmp.length() != 0)
23
+ sta.push(tmp);
24
+ }
25
+
26
+ s.erase(0, s.length());
27
+ while(!sta.empty())
28
+ {
29
+ s += sta.top();
30
+ sta.pop();
31
+ if(!sta.empty())
32
+ s += " ";
33
+ }
34
+ }
35
+ };
You can’t perform that action at this time.
0 commit comments