Skip to content

Commit 4cf7b94

Browse files
committed
add code
1 parent 96876eb commit 4cf7b94

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <string>
2+
#include <algorithm>
3+
using namespace std;
4+
/*
5+
* @lc app=leetcode.cn id=1668 lang=cpp
6+
*
7+
* [1668] 最大重复子字符串
8+
*/
9+
10+
// @lc code=start
11+
class Solution {
12+
public:
13+
int maxRepeating(string sequence, string word) {
14+
if (sequence.size() < word.size()) {
15+
return 0;
16+
}
17+
int rM = 0;
18+
int r = 0;
19+
20+
for (int k = 0; k < sequence.size() - word.size() + 1; k++){
21+
for (int i = k; i < sequence.size() - word.size() + 1; i++) {
22+
bool isS = true;
23+
for (int j = 0; j < word.size(); j++) {
24+
if (sequence[i + j] != word[j]) {
25+
isS = false;
26+
break;
27+
}
28+
}
29+
if (isS) {
30+
r++;
31+
i += word.size() - 1;
32+
} else {
33+
break;
34+
}
35+
}
36+
rM = max(rM, r);
37+
r = 0;
38+
}
39+
return rM;
40+
}
41+
};
42+
// @lc code=end
43+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* @lc app=leetcode.cn id=1684 lang=cpp
3+
*
4+
* [1684] 统计一致字符串的数目
5+
*/
6+
#include <set>
7+
#include <string>
8+
#include <vector>
9+
using namespace std;
10+
11+
// @lc code=start
12+
class Solution {
13+
public:
14+
int countConsistentStrings(string allowed, vector<string>& words) {
15+
set<char> s;
16+
for (size_t i = 0; i < allowed.size(); i++) {
17+
s.insert(allowed[i]);
18+
}
19+
20+
int sum = 0;
21+
22+
for (size_t i = 0; i < words.size(); i++) {
23+
bool is_ok = true;
24+
for (size_t j = 0; j < words[i].size(); j++) {
25+
if (s.count(words[i][j]) == 0) {
26+
is_ok = false;
27+
break;
28+
}
29+
}
30+
if (is_ok) {
31+
sum++;
32+
}
33+
}
34+
return sum;
35+
}
36+
};
37+
// @lc code=end
38+

code/816.模糊坐标.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* @lc app=leetcode.cn id=816 lang=cpp
3+
*
4+
* [816] 模糊坐标
5+
*/
6+
#include <vector>
7+
#include <string>
8+
using namespace std;
9+
// @lc code=start
10+
class Solution {
11+
private:
12+
vector<string> rs;
13+
14+
bool checkDigit(string s, int i) {
15+
if (s.size() != 1) {
16+
if (s[0] == '0' && i != 1) {
17+
return false;
18+
}
19+
if (i != 0 && s[s.size() - 1] == '0') {
20+
return false;
21+
}
22+
}
23+
return true;
24+
}
25+
26+
string makeStr(string a, string b) {
27+
return "(" + a + ", " + b + ")";
28+
}
29+
30+
string genStr(string a, int i) {
31+
if (i == 0) {
32+
return a;
33+
}
34+
return a.substr(0, i) + "." + a.substr(i, a.size());
35+
}
36+
37+
void aC(string s, int i) {
38+
if (i >= s.size()) {
39+
return;
40+
}
41+
string a = s.substr(0, i);
42+
string b = s.substr(i, s.size() - i);
43+
44+
for(int i = 0; i < a.size(); i++) {
45+
string s1 = genStr(a, i);
46+
if (checkDigit(s1, i)) {
47+
for (size_t j = 0; j < b.size(); j++) {
48+
string s2 = genStr(b, j);
49+
if (checkDigit(s2, j)) {
50+
rs.push_back(makeStr(s1, s2));
51+
}
52+
}
53+
54+
}
55+
}
56+
aC(s, i + 1);
57+
}
58+
public:
59+
vector<string> ambiguousCoordinates(string s) {
60+
rs.clear();
61+
aC(s.substr(1, s.size() - 2), 1);
62+
return rs;
63+
}
64+
};
65+
// @lc code=end
66+

0 commit comments

Comments
 (0)