Skip to content

Commit 3ac0bac

Browse files
committed
3重ループを1重にしたコードを追加
1 parent b49e57c commit 3ac0bac

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

125/4.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// 3重ループを1重ループとしたコード
2+
class Solution {
3+
public:
4+
bool isPalindrome(string s) {
5+
if (s.empty()) abort();
6+
int left = 0, right = s.size()-1;
7+
8+
while (left < right) {
9+
if (!isalnum(s[left])) {
10+
left++;
11+
continue;
12+
}
13+
14+
if (!isalnum(s[right])) {
15+
right--;
16+
continue;
17+
}
18+
19+
if (tolower(s[left]) != tolower(s[right])) {
20+
return false;
21+
}
22+
23+
left++;
24+
right--;
25+
}
26+
27+
return true;
28+
}
29+
};

0 commit comments

Comments
 (0)