-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetCode.h
More file actions
177 lines (143 loc) · 3.75 KB
/
LeetCode.h
File metadata and controls
177 lines (143 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#pragma once
#include <string>
#include <vector>
#include <memory>
#include <cassert>
class LeetCode
{
public:
// 746. 使用最小花费爬楼梯
static void
minCostClimbingStairs();
// 844. 比较含退格的字符串
static void
backspaceCompare();
// 986. 区间列表的交集
static void
intervalIntersection();
// 438. 找到字符串中所有字母异位词
static void
findAnagrams();
// 713. 乘积小于K的子数组
static void
numSubarrayProductLessThanK();
// 509 斐波那契 数
static void
fib();
// 1137 1137. 第 N 个泰波那契数
static void
tribonacci();
// 797. 所有可能的路径
static void
allPathsSourceTarget();
// 494. 目标和
static void
findTargetSumWays();
static void
remove_all_words();
static int
maxConsecutive(int bottom, int top, std::vector<int> &special);
static int
largestCombination();
// 2243. 计算字符串的数字和
static void
digitSum();
// 2248. 多个数组求交集
static void intersection();
// countLatticePoints 2249. 统计圆内格点数目
static void countLatticePoints();
// 2549. 统计桌面上的不同数字
static void distinctIntegers();
//2551
static void putMarbles();
class CountIntervals
{
std::vector<std::pair<int, int>> m_con;
public:
CountIntervals() = default;
void
add(int left, int right)
{
this->insert(left, right);
this->set();
}
int
count()
{
int count = 0;
for (std::pair<int, int> &a : this->m_con)
{
count += a.second - a.first + 1;
}
return count;
}
void
insert(int left, int right)
{
auto size = this->m_con.size();
int cur = 0;
for (int i = 0; i < size; ++i)
{
if (this->m_con[i].first && this->m_con[i].second)
{
}
}
}
void
set()
{
// 合并当前的
}
};
private:
struct ListNode
{
ListNode() : val(0), next{nullptr} {}
explicit ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode *raw_ptr) : val(x), next(raw_ptr) {}
ListNode(const ListNode &) = delete;
ListNode *next;
int val;
static std::unique_ptr<ListNode>
new_list(size_t length)
{
assert(length != 0);
auto result = std::make_unique<ListNode>(0);
result->node.reserve(length - 1);
auto root = result.get();
for (size_t i = 1; i < length; i++)
{
root->next = new ListNode(i);
root = root->next;
result->node.emplace_back(root);
}
return result;
}
static std::unique_ptr<ListNode>
new_list(const std::vector<int> &data)
{
if (data.empty())
return nullptr;
auto result = std::make_unique<ListNode>(data[0]);
auto root = result.get();
result->node.reserve(data.size() - 1);
size_t size = data.size();
for (size_t i = 1; i < size; i++)
{
root->next = new ListNode(data[i]);
root = root->next;
result->node.emplace_back(root);
}
return result;
}
~ListNode()
{
for (auto data : node)
{
delete data;
}
}
private:
std::vector<ListNode *> node = {};
};
};