Skip to content

Commit 2defbeb

Browse files
committed
feat: add solutions to lc problems: No.2351~2354
* No.2351.First Letter to Appear Twice * No.2352.Equal Row and Column Pairs * No.2353.Design a Food Rating System * No.2354.Number of Excellent Pairs
1 parent cbaa988 commit 2defbeb

File tree

36 files changed

+3974
-3060
lines changed

36 files changed

+3974
-3060
lines changed

lcof2/剑指 Offer II 043. 往完全二叉树添加节点/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class CBTInserter {
136136
}
137137
}
138138
}
139-
139+
140140
public int insert(int v) {
141141
int pid = (tree.size() - 1) >> 1;
142142
TreeNode node = new TreeNode(v);
@@ -149,7 +149,7 @@ class CBTInserter {
149149
}
150150
return p.val;
151151
}
152-
152+
153153
public TreeNode get_root() {
154154
return tree.get(0);
155155
}
@@ -192,7 +192,7 @@ public:
192192
if (node->right) q.push(node->right);
193193
}
194194
}
195-
195+
196196
int insert(int v) {
197197
int pid = tree.size() - 1 >> 1;
198198
TreeNode* node = new TreeNode(v);
@@ -202,7 +202,7 @@ public:
202202
else p->right = node;
203203
return p->val;
204204
}
205-
205+
206206
TreeNode* get_root() {
207207
return tree[0];
208208
}

solution/0900-0999/0919.Complete Binary Tree Inserter/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class CBTInserter {
141141
}
142142
}
143143
}
144-
144+
145145
public int insert(int val) {
146146
int pid = (tree.size() - 1) >> 1;
147147
TreeNode node = new TreeNode(val);
@@ -154,7 +154,7 @@ class CBTInserter {
154154
}
155155
return p.val;
156156
}
157-
157+
158158
public TreeNode get_root() {
159159
return tree.get(0);
160160
}
@@ -197,7 +197,7 @@ public:
197197
if (node->right) q.push(node->right);
198198
}
199199
}
200-
200+
201201
int insert(int val) {
202202
int pid = tree.size() - 1 >> 1;
203203
TreeNode* node = new TreeNode(val);
@@ -207,7 +207,7 @@ public:
207207
else p->right = node;
208208
return p->val;
209209
}
210-
210+
211211
TreeNode* get_root() {
212212
return tree[0];
213213
}

solution/0900-0999/0919.Complete Binary Tree Inserter/README_EN.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class CBTInserter {
128128
}
129129
}
130130
}
131-
131+
132132
public int insert(int val) {
133133
int pid = (tree.size() - 1) >> 1;
134134
TreeNode node = new TreeNode(val);
@@ -141,7 +141,7 @@ class CBTInserter {
141141
}
142142
return p.val;
143143
}
144-
144+
145145
public TreeNode get_root() {
146146
return tree.get(0);
147147
}
@@ -184,7 +184,7 @@ public:
184184
if (node->right) q.push(node->right);
185185
}
186186
}
187-
187+
188188
int insert(int val) {
189189
int pid = tree.size() - 1 >> 1;
190190
TreeNode* node = new TreeNode(val);
@@ -194,7 +194,7 @@ public:
194194
else p->right = node;
195195
return p->val;
196196
}
197-
197+
198198
TreeNode* get_root() {
199199
return tree[0];
200200
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
class Solution:
2-
def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
2+
def distanceBetweenBusStops(
3+
self, distance: List[int], start: int, destination: int
4+
) -> int:
35
if start > destination:
46
start, destination = destination, start
5-
a = sum(distance[start: destination])
7+
a = sum(distance[start:destination])
68
b = sum(distance[:start]) + sum(distance[destination:])
79
return min(a, b)

solution/2000-2099/2062.Count Vowel Substrings of a String/Solution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ class Solution:
22
def countVowelSubstrings(self, word: str) -> int:
33
n = len(word)
44
s = set('aeiou')
5-
return sum(set(word[i: j]) == s for i in range(n) for j in range(i + 1, n + 1))
5+
return sum(set(word[i:j]) == s for i in range(n) for j in range(i + 1, n + 1))

solution/2300-2399/2348.Number of Zero-Filled Subarrays/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
4949
</ul>
5050

51-
5251
## 解法
5352

5453
<!-- 这里可写通用的实现逻辑 -->

solution/2300-2399/2348.Number of Zero-Filled Subarrays/README_EN.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ There is no occurrence of a subarray with a size more than 3 filled with 0. Ther
4747
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
4848
</ul>
4949

50-
5150
## Solutions
5251

5352
<!-- tabs:start -->

solution/2300-2399/2349.Design a Number Container System/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ nc.find(10); // 数字 10 所在下标为 2 ,3 和 5 。最小下标为 2 ,
5353
<li>调用&nbsp;<code>change</code> 和&nbsp;<code>find</code>&nbsp;的&nbsp;<strong>总次数</strong>&nbsp;不超过&nbsp;<code>10<sup>5</sup></code> 次。</li>
5454
</ul>
5555

56-
5756
## 解法
5857

5958
<!-- 这里可写通用的实现逻辑 -->
@@ -106,7 +105,7 @@ class NumberContainers {
106105
public NumberContainers() {
107106

108107
}
109-
108+
110109
public void change(int index, int number) {
111110
if (mp.containsKey(index)) {
112111
int v = mp.get(index);
@@ -118,7 +117,7 @@ class NumberContainers {
118117
mp.put(index, number);
119118
t.computeIfAbsent(number, k -> new TreeSet<>()).add(index);
120119
}
121-
120+
122121
public int find(int number) {
123122
return t.containsKey(number) ? t.get(number).first() : -1;
124123
}
@@ -143,7 +142,7 @@ public:
143142
NumberContainers() {
144143

145144
}
146-
145+
147146
void change(int index, int number) {
148147
auto it = mp.find(index);
149148
if (it != mp.end())
@@ -154,7 +153,7 @@ public:
154153
else mp[index] = number;
155154
t[number].insert(index);
156155
}
157-
156+
158157
int find(int number) {
159158
auto it = t.find(number);
160159
return it == t.end() || it->second.empty() ? -1 : *it->second.begin();

solution/2300-2399/2349.Design a Number Container System/README_EN.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ nc.find(10); // Number 10 is at the indices 2, 3, and 5. The smallest index that
4949
<li>At most <code>10<sup>5</sup></code> calls will be made <strong>in total</strong> to <code>change</code> and <code>find</code>.</li>
5050
</ul>
5151

52-
5352
## Solutions
5453

5554
<!-- tabs:start -->
@@ -94,7 +93,7 @@ class NumberContainers {
9493
public NumberContainers() {
9594

9695
}
97-
96+
9897
public void change(int index, int number) {
9998
if (mp.containsKey(index)) {
10099
int v = mp.get(index);
@@ -106,7 +105,7 @@ class NumberContainers {
106105
mp.put(index, number);
107106
t.computeIfAbsent(number, k -> new TreeSet<>()).add(index);
108107
}
109-
108+
110109
public int find(int number) {
111110
return t.containsKey(number) ? t.get(number).first() : -1;
112111
}
@@ -131,7 +130,7 @@ public:
131130
NumberContainers() {
132131

133132
}
134-
133+
135134
void change(int index, int number) {
136135
auto it = mp.find(index);
137136
if (it != mp.end())
@@ -142,7 +141,7 @@ public:
142141
else mp[index] = number;
143142
t[number].insert(index);
144143
}
145-
144+
146145
int find(int number) {
147146
auto it = t.find(number);
148147
return it == t.end() || it->second.empty() ? -1 : *it->second.begin();

solution/2300-2399/2349.Design a Number Container System/Solution.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class NumberContainers:
5-
65
def __init__(self):
76
self.mp = {}
87
self.t = defaultdict(SortedSet)

0 commit comments

Comments
 (0)