Merge 133fe1efcf924680082f1f83e0dbb3206d79c37a into b70121d377cb6005eb65f12b098cd5decd905669

This commit is contained in:
LeyaoW 2023-08-04 08:30:09 +00:00 committed by GitHub
commit 041d5e1fb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,7 @@
* [9. 统计二进制字符串中连续 1 和连续 0 数量相同的子字符串个数](#9-统计二进制字符串中连续-1-和连续-0-数量相同的子字符串个数) * [9. 统计二进制字符串中连续 1 和连续 0 数量相同的子字符串个数](#9-统计二进制字符串中连续-1-和连续-0-数量相同的子字符串个数)
<!-- GFM-TOC --> <!-- GFM-TOC -->
字符串问题可以使用HashMap记录每个字母出现的个数进一步简化为使用arrayindex是字母的ACII值index对应的数就是字母出现的个数。
## 1. 字符串循环移位包含 ## 1. 字符串循环移位包含
[编程之美 3.1](#) [编程之美 3.1](#)
@ -206,6 +206,25 @@ public boolean isPalindrome(int x) {
return x == right || x == right / 10; return x == right || x == right / 10;
} }
``` ```
我自己的解法C++:使用to_string把整数转换成string带正负符号
``` c++
class Solution {
public:
bool isPalindrome(int x) {
string s=to_string(x);
int start=0;
int end=s.length()-1;
while(start<=end){
if (s[start]!=s[end]){
return false;
}
start++;
end--;
}
return true;
}
};
```
## 9. 统计二进制字符串中连续 1 和连续 0 数量相同的子字符串个数 ## 9. 统计二进制字符串中连续 1 和连续 0 数量相同的子字符串个数