- leetcode459-重复的子字符串
题型:字符串
难度:简单
题目:给定一个非空的字符串,判断它是否可以由它的一个子串重复多次构成。给定的字符串只含有小写英文字母,并且长度不超过10000。
代码:
class Solution {
public:
bool repeatedSubstringPattern(string s) {
string temp = s+s;
if(temp.find(s,1) != s.size())
return true;
return false;
}
};
- leetcode9-回文数
题型:回文数
难度:简单
题目:判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。
代码:
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0) return false;
if(x>=0 && x<=9) return true;
if(x>=INT_MAX) return false;
int temp = x;
int rightnum = 0;
while(temp)
{
int n = temp%10;
temp /= 10;
rightnum = rightnum*10+n;
}
if(x == rightnum) return true;
return false;
}
};