Skip to content

Commit 0a524db

Browse files
committed
update
1 parent 94fa798 commit 0a524db

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution {
2+
public:
3+
4+
string longestPalindrome(string s) {
5+
if (s.length() < 1) return "";
6+
int len1, len2, len,maxlen=0;
7+
int start = 0, end = 0;
8+
for (int i = 0; i < s.length(); i++) {
9+
len1 = expandAroundCenter(s, i, i);
10+
len2 = expandAroundCenter(s, i, i + 1);
11+
len = max(len1, len2);
12+
if (len > maxlen) maxlen = len;
13+
if (len > end - start) {
14+
start = i - (len - 1) / 2;
15+
end = i + len / 2;
16+
//cout << i << " " << start << " " << end << " " << len << endl;
17+
}
18+
}
19+
//cout << start << " " << end << " " << len << endl;
20+
return s.substr(start, maxlen);//参考的solution 结果Java的substring是[start,end),C++的string是(start,length)因为随着遍历len可能还会变小,所以留存最大的len
21+
}
22+
`private:`
23+
`int expandAroundCenter(string s,int left,int right){`
24+
`int L=left,R=right;`
25+
`while(L>=0&&R<s.length()&&s[L]==s[R]){`
26+
`L--;`
27+
`R++;`
28+
`}`
29+
`return R-L-1;`
30+
`}`
31+
`};`

LeetCode/709. To Lower Case.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public:
3+
//'a'-32='A'
4+
string toLowerCase(string str) {
5+
for (char& c : str) {
6+
if (c >= 'A' && c <= 'Z') c += 32;
7+
}
8+
return str;
9+
}
10+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
string m[27]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
3+
public:
4+
int uniqueMorseRepresentations(vector<string>& words) {
5+
vector<string> d = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
6+
unordered_set<string> s;
7+
for (auto word : words) {
8+
string code;
9+
for (auto c : word) code += d[c - 'a'];
10+
s.insert(code);
11+
}
12+
return s.size();
13+
}
14+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
int numUniqueEmails(vector<string>& emails) {
4+
unordered_set<string> s;
5+
for(auto email:emails){
6+
string str;
7+
auto it = email.begin();
8+
for (; '@' != *it && '+' != *it; ++it) {
9+
if ('.' != *it) {
10+
str += *it;
11+
}
12+
}
13+
it=find(it, email.end(), '@');
14+
str.append(it, email.end());
15+
s.insert(str);
16+
}
17+
return s.size();
18+
}
19+
};

0 commit comments

Comments
 (0)