Skip to content

Commit 81ac2e7

Browse files
committed
8.17
1 parent 008b820 commit 81ac2e7

33 files changed

+1969
-318
lines changed

.vscode/settings.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
22
"files.associations": {
3-
"vector": "cpp"
3+
"vector": "cpp",
4+
"iostream": "cpp",
5+
"string": "cpp",
6+
"ostream": "cpp",
7+
"__split_buffer": "cpp",
8+
"deque": "cpp",
9+
"list": "cpp",
10+
"iosfwd": "cpp"
411
}
512
}

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
-------
33

44
#### 文件说明
5+
模版文件夹下
56
socution.cpp:模版(适用于牛客,赛码等)
67
method.cpp:常用算法
78

89
#### 作者
910
author: 孟凡宇
1011
11-
website: www.mengfanyu.com
12+
website: www.mengfanyu.com
13+
14+

leetcode/336_hui_wen_shu.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "include.h"
2+
3+
class Solution {
4+
public:
5+
vector<vector<int> > palindromePairs(vector<string>& words) {
6+
vector<vector<int> > result;
7+
for(int i = 0; i < words.size(); i++){
8+
for(int j = 0; j < words.size(); j++){
9+
if(j == i) continue;
10+
if(canCompose(words, i, j)){
11+
result.push_back({i,j});
12+
}
13+
}
14+
}
15+
return result;
16+
}
17+
bool canCompose(vector<string>& words, int i, int j){
18+
string word = words[i] + words[j];
19+
cout << "compsing : " << i << "and" << j << " ";
20+
for(int k = 0; k < word.size() / 2; ++k){
21+
if(word[k] != word[word.size() - k - 1]){
22+
cout << "index "<< k <<"not compsed" <<endl;
23+
return false;
24+
}
25+
}
26+
cout <<endl;
27+
return true;
28+
}
29+
};
30+
31+
int main(int argc, char const *argv[])
32+
{
33+
vector<string> words{"abcd","dcba","lls","s","sssll"};
34+
Solution *method = new Solution();
35+
vector<vector<int> > result;
36+
result = method->palindromePairs(words);
37+
for(auto item : result){
38+
cout << item[0] << "," << item[1] << endl;
39+
}
40+
return 0;
41+
}

leetcode/leetcode45.cpp

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include "include.h"
2+
3+
using namespace std;
4+
5+
class Solution {
6+
public:
7+
static bool cmp(string str1, string str2) {
8+
// if(str1.size() == str2.size()) return str1 < str2;
9+
int minsize = min(str1.size(), str2.size());
10+
int maxsize = max(str1.size(), str2.size());
11+
// cout << str1<<":"<<str2<<endl;
12+
for(int i = 0;i < minsize;i++){
13+
if(str1[i] != str2[i]){
14+
return str1[i] < str2[i];
15+
}
16+
}
17+
18+
if(maxsize == str1.size()){
19+
for(int i = minsize;i < maxsize;i++){
20+
if(str1[i] != str1[minsize - 1]){
21+
return str1[i] < str1[minsize - 1];
22+
}
23+
}
24+
}
25+
if(maxsize == str2.size()){
26+
for(int i = minsize;i < maxsize;i++){
27+
if(str2[i] != str2[minsize - 1]){
28+
// cout << str2[i] << str1[minsize - 1]<<endl;
29+
return str2[i] < str2[minsize - 1];
30+
}
31+
}
32+
}
33+
return false;
34+
}
35+
36+
string minNumber(vector<int>& nums) {
37+
// sort(nums.begin(), nums.end());
38+
vector<string> strvec;
39+
for(auto num : nums){
40+
strvec.push_back(to_string(num));
41+
}
42+
sort(strvec.begin(),strvec.end(),cmp);
43+
for(auto s : strvec){
44+
cout << s<<" ";
45+
}
46+
string result;
47+
for(auto str : strvec){
48+
// cout << str;
49+
result.append(str);
50+
}
51+
// cout << endl;
52+
return result;
53+
}
54+
};
55+
56+
int main(int argc, char const *argv[])
57+
{
58+
vector<int> input;
59+
input.push_back(102);
60+
input.push_back(10);
61+
Solution *method = new Solution();
62+
cout << method->minNumber(input);
63+
return 0;
64+
}

leetcode/leetcode696.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "include.h"
2+
3+
class Solution {
4+
public:
5+
int countBinarySubstrings(string s) {
6+
if(s.size() == 1) return 0;
7+
int result = 0;
8+
// int count0 = 0, count1 = 0;
9+
int left0 = 0, left1 = 0, right0 = 1,right1 = 1;
10+
for(int i = 1; i < s.size(); i++){
11+
if(s[i] != s[i-1]){
12+
result += min(right0 - left0, right1 - left1);
13+
if(s[i] == '0'){
14+
left0 = i;
15+
right0 = i+1;
16+
}
17+
if(s[i] == '1'){
18+
left1 = i;
19+
right1 = i+1;
20+
}
21+
}else{
22+
if(s[i] == '0'){
23+
right0 = i+1;
24+
}
25+
if(s[i] == '1'){
26+
right1 = i+1;
27+
}
28+
}
29+
}
30+
// result += min(right0 - left0, right1 - left1);
31+
return result;
32+
}
33+
};
34+
35+
int main(int argc, char const *argv[])
36+
{
37+
Solution *method = new Solution();
38+
cout << method->countBinarySubstrings("00110");
39+
return 0;
40+
}

method.cpp

-78
This file was deleted.

method.h

-52
This file was deleted.

solution

-15.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)