This commit is contained in:
2025-09-15 21:12:04 +08:00
commit 3f58f483ff
144 changed files with 5298 additions and 0 deletions

50
23/11/Q117.h Normal file
View File

@@ -0,0 +1,50 @@
//
// Created by 李洋 on 2023/11/3.
//
#ifndef LEECODE_C_Q117_H
#define LEECODE_C_Q117_H
#include <stack>
#include <queue>
using namespace std;
class Node {
public:
int val;
Node *left;
Node *right;
Node *next;
Node() : val(0), left(nullptr), right(nullptr), next(nullptr) {}
Node(int _val) : val(_val), left(nullptr), right(nullptr), next(nullptr) {}
Node(int _val, Node *_left, Node *_right, Node *_next)
: val(_val), left(_left), right(_right), next(_next) {}
};
Node *connect(Node *root) {
if (!root) {
return nullptr;
}
queue<pair<Node *, int>> Q;
Q.emplace(root, 1);
while (!Q.empty()) {
auto temp = Q.front();
Q.pop();
if (temp.second == Q.front().second) {
temp.first->next = Q.front().first;
}
if (temp.first->left != nullptr) {
Q.emplace(temp.first->left, temp.second + 1);
}
if (temp.first->right != nullptr) {
Q.emplace(temp.first->right, temp.second + 1);
}
}
return root;
}
#endif //LEECODE_C_Q117_H

28
23/11/Q187.h Normal file
View File

@@ -0,0 +1,28 @@
//
// Created by 李洋 on 2023/11/5.
//
#ifndef LEECODE_C_Q187_H
#define LEECODE_C_Q187_H
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
vector<string> findRepeatedDnaSequences(string s) {
vector<string> ret;
unordered_map<string, int> m;
for(int i = 0;i+9<s.length();i++){
m[s.substr(i,i+9)] = m[s.substr(i,i+9)] + 1;
}
for(auto [key,value]:m){
if(value > 1){
ret.push_back(key);
}
}
return ret;
}
#endif //LEECODE_C_Q187_H

28
23/11/Q2342.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef LEECODE_C_Q2342_H
#define LEECODE_C_Q2342_H
#include <vector>
#include <map>
using namespace std;
int maximumSum(vector<int> &nums)
{
int ans = -1;
int mx[82]{}; // 至多 9 个 9 相加
for (int num : nums)
{
int s = 0; // num 的数位和
for (int x = num; x; x /= 10)
{ // 枚举 num 的每个数位
s += x % 10;
}
if (mx[s])
{ // 说明左边也有数位和等于 s 的元素
ans = max(ans, mx[s] + num); // 更新答案的最大值
}
mx[s] = max(mx[s], num); // 维护数位和等于 s 的最大元素
}
return ans;
}
#endif LEECODE_C_Q2342_H

31
23/11/Q2586.h Normal file
View File

@@ -0,0 +1,31 @@
//
// Created by 李洋 on 2023/11/8.
//
#ifndef LEECODE_C_Q2586_H
#define LEECODE_C_Q2586_H
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
int vowelStrings(vector<string> &words, int left, int right) {
unordered_map<char, int> m;
m['a'] = 1;
m['e'] = 1;
m['i'] = 1;
m['o'] = 1;
m['u'] = 1;
int count = 0;
for (int i = left; i <= right; ++i) {
auto s = words[i];
if (s != "" && m[s[0]] && m[s[s.length() - 1]]) {
count++;
}
}
return count;
}
#endif //LEECODE_C_Q2586_H

25
23/11/Q2609.h Normal file
View File

@@ -0,0 +1,25 @@
//
// Created by 李洋 on 2023/11/8.
//
#ifndef LEECODE_C_Q2609_H
#define LEECODE_C_Q2609_H
#include <string>
#include <vector>
#include <stack>
using namespace std;
int findTheLongestBalancedSubstring(string s) {
int n = s.size(), idx = 0, ans = 0;
while (idx < n) {
int a = 0, b = 0;
while (idx < n && s[idx] == '0' && ++a >= 0) idx++;
while (idx < n && s[idx] == '1' && ++b >= 0) idx++;
ans = max(ans, min(a, b) * 2);
}
return ans;
}
#endif //LEECODE_C_Q2609_H

17
23/11/Q318.h Normal file
View File

@@ -0,0 +1,17 @@
//
// Created by 李洋 on 2023/11/6.
//
#ifndef LEECODE_C_Q318_H
#define LEECODE_C_Q318_H
#include <string>
#include <vector>
using namespace std;
int maxProduct(vector<string> &words) {
}
#endif //LEECODE_C_Q318_H

33
23/11/Q876.h Normal file
View File

@@ -0,0 +1,33 @@
//
// Created by 李洋 on 2023/11/7.
//
#ifndef LEECODE_C_Q876_H
#define LEECODE_C_Q876_H
#include <vector>
#include <stack>
using namespace std;
struct ListNode {
int val;
ListNode *next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode *next) : val(x), next(next) {}
};
ListNode *middleNode(ListNode *head) {
ListNode *slow = head, *fast = head;
while (fast && fast->next) {
slow = slow->next;
fast = fast->next->next;
}
return slow;
}
#endif //LEECODE_C_Q876_H