= new Map();
+ for (let p2 of points) {
+ const distance = (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2;
+ hashMap.set(distance, (hashMap.get(distance) || 0) + 1);
}
- return ans;
-};
+ for (let [, v] of [...hashMap]) {
+ ans += v * (v - 1);
+ }
+ }
+ return ans;
+}
```
### **Go**
diff --git a/solution/0400-0499/0447.Number of Boomerangs/Solution.py b/solution/0400-0499/0447.Number of Boomerangs/Solution.py
index 39ff50ee6727d..fad84640e2dd3 100644
--- a/solution/0400-0499/0447.Number of Boomerangs/Solution.py
+++ b/solution/0400-0499/0447.Number of Boomerangs/Solution.py
@@ -2,9 +2,10 @@ class Solution:
def numberOfBoomerangs(self, points: List[List[int]]) -> int:
ans = 0
for p in points:
- counter = collections.Counter()
+ counter = Counter()
for q in points:
- distance = (p[0] - q[0]) * (p[0] - q[0]) + (p[1] - q[1]) * (p[1] - q[1])
+ distance = (p[0] - q[0]) * (p[0] - q[0]) + \
+ (p[1] - q[1]) * (p[1] - q[1])
counter[distance] += 1
ans += sum([val * (val - 1) for val in counter.values()])
return ans
diff --git a/solution/0400-0499/0451.Sort Characters By Frequency/README.md b/solution/0400-0499/0451.Sort Characters By Frequency/README.md
index 1739d1652ce9f..b5e89a66f294e 100644
--- a/solution/0400-0499/0451.Sort Characters By Frequency/README.md
+++ b/solution/0400-0499/0451.Sort Characters By Frequency/README.md
@@ -65,8 +65,8 @@
```python
class Solution:
def frequencySort(self, s: str) -> str:
- counter = collections.Counter(s)
- buckets = collections.defaultdict(list)
+ counter = Counter(s)
+ buckets = defaultdict(list)
for c, freq in counter.items():
buckets[freq].append(c)
res = []
diff --git a/solution/0400-0499/0451.Sort Characters By Frequency/README_EN.md b/solution/0400-0499/0451.Sort Characters By Frequency/README_EN.md
index 8f7ea7aaf768a..f92d9a49784dd 100644
--- a/solution/0400-0499/0451.Sort Characters By Frequency/README_EN.md
+++ b/solution/0400-0499/0451.Sort Characters By Frequency/README_EN.md
@@ -51,8 +51,8 @@ Note that 'A' and 'a' are treated as two different characters.
```python
class Solution:
def frequencySort(self, s: str) -> str:
- counter = collections.Counter(s)
- buckets = collections.defaultdict(list)
+ counter = Counter(s)
+ buckets = defaultdict(list)
for c, freq in counter.items():
buckets[freq].append(c)
res = []
diff --git a/solution/0400-0499/0451.Sort Characters By Frequency/Solution.py b/solution/0400-0499/0451.Sort Characters By Frequency/Solution.py
index 45570cd0284a9..538e162bc8ef2 100644
--- a/solution/0400-0499/0451.Sort Characters By Frequency/Solution.py
+++ b/solution/0400-0499/0451.Sort Characters By Frequency/Solution.py
@@ -1,7 +1,7 @@
class Solution:
def frequencySort(self, s: str) -> str:
- counter = collections.Counter(s)
- buckets = collections.defaultdict(list)
+ counter = Counter(s)
+ buckets = defaultdict(list)
for c, freq in counter.items():
buckets[freq].append(c)
res = []
diff --git a/solution/0500-0599/0533.Lonely Pixel II/README.md b/solution/0500-0599/0533.Lonely Pixel II/README.md
index 19182b53676cf..990aa3803c2c3 100644
--- a/solution/0500-0599/0533.Lonely Pixel II/README.md
+++ b/solution/0500-0599/0533.Lonely Pixel II/README.md
@@ -66,7 +66,7 @@ class Solution:
def findBlackPixel(self, picture: List[List[str]], target: int) -> int:
m, n = len(picture), len(picture[0])
rows = [0] * m
- cols = collections.defaultdict(list)
+ cols = defaultdict(list)
for i in range(m):
for j in range(n):
if picture[i][j] == 'B':
diff --git a/solution/0500-0599/0533.Lonely Pixel II/README_EN.md b/solution/0500-0599/0533.Lonely Pixel II/README_EN.md
index 6dba0bd5b2fdf..09a86910e0e2c 100644
--- a/solution/0500-0599/0533.Lonely Pixel II/README_EN.md
+++ b/solution/0500-0599/0533.Lonely Pixel II/README_EN.md
@@ -85,7 +85,7 @@ class Solution:
def findBlackPixel(self, picture: List[List[str]], target: int) -> int:
m, n = len(picture), len(picture[0])
rows = [0] * m
- cols = collections.defaultdict(list)
+ cols = defaultdict(list)
for i in range(m):
for j in range(n):
if picture[i][j] == 'B':
diff --git a/solution/0500-0599/0533.Lonely Pixel II/Solution.py b/solution/0500-0599/0533.Lonely Pixel II/Solution.py
index d6400a3a9c40e..a51ce58767c71 100644
--- a/solution/0500-0599/0533.Lonely Pixel II/Solution.py
+++ b/solution/0500-0599/0533.Lonely Pixel II/Solution.py
@@ -2,7 +2,7 @@ class Solution:
def findBlackPixel(self, picture: List[List[str]], target: int) -> int:
m, n = len(picture), len(picture[0])
rows = [0] * m
- cols = collections.defaultdict(list)
+ cols = defaultdict(list)
for i in range(m):
for j in range(n):
if picture[i][j] == 'B':
@@ -14,7 +14,8 @@ def findBlackPixel(self, picture: List[List[str]], target: int) -> int:
if i == k:
t[i][k] = True
else:
- t[i][k] = all([picture[i][j] == picture[k][j] for j in range(n)])
+ t[i][k] = all([picture[i][j] == picture[k][j]
+ for j in range(n)])
t[k][i] = t[i][k]
res = 0
for i in range(m):
diff --git a/solution/0500-0599/0554.Brick Wall/README.md b/solution/0500-0599/0554.Brick Wall/README.md
index 3295b325b5d0e..792444c37fc59 100644
--- a/solution/0500-0599/0554.Brick Wall/README.md
+++ b/solution/0500-0599/0554.Brick Wall/README.md
@@ -55,7 +55,7 @@
```python
class Solution:
def leastBricks(self, wall: List[List[int]]) -> int:
- cnt = collections.defaultdict(int)
+ cnt = defaultdict(int)
for row in wall:
width = 0
for brick in row[:-1]:
diff --git a/solution/0500-0599/0554.Brick Wall/README_EN.md b/solution/0500-0599/0554.Brick Wall/README_EN.md
index dcf43abe415cc..e46627a2015be 100644
--- a/solution/0500-0599/0554.Brick Wall/README_EN.md
+++ b/solution/0500-0599/0554.Brick Wall/README_EN.md
@@ -62,7 +62,7 @@ The question can be understood as, let the vertical line pass through the edge o
```python
class Solution:
def leastBricks(self, wall: List[List[int]]) -> int:
- cnt = collections.defaultdict(int)
+ cnt = defaultdict(int)
for row in wall:
width = 0
for brick in row[:-1]:
diff --git a/solution/0500-0599/0554.Brick Wall/Solution.py b/solution/0500-0599/0554.Brick Wall/Solution.py
index c9df2756ee93a..cfd160aa3d1f3 100644
--- a/solution/0500-0599/0554.Brick Wall/Solution.py
+++ b/solution/0500-0599/0554.Brick Wall/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def leastBricks(self, wall: List[List[int]]) -> int:
- cnt = collections.defaultdict(int)
+ cnt = defaultdict(int)
for row in wall:
width = 0
for brick in row[:-1]:
diff --git a/solution/0500-0599/0560.Subarray Sum Equals K/README.md b/solution/0500-0599/0560.Subarray Sum Equals K/README.md
index 1076236a2d911..12e2c13cb2d6c 100644
--- a/solution/0500-0599/0560.Subarray Sum Equals K/README.md
+++ b/solution/0500-0599/0560.Subarray Sum Equals K/README.md
@@ -1,4 +1,4 @@
-# [560. 和为K的子数组](https://leetcode-cn.com/problems/subarray-sum-equals-k)
+# [560. 和为 K 的子数组](https://leetcode-cn.com/problems/subarray-sum-equals-k)
[English Version](/solution/0500-0599/0560.Subarray%20Sum%20Equals%20K/README_EN.md)
@@ -22,7 +22,6 @@
数组中元素的范围是 [-1000, 1000] ,且整数 k 的范围是 [-1e7, 1e7]。
-
## 解法
@@ -36,7 +35,7 @@
```python
class Solution:
def subarraySum(self, nums: List[int], k: int) -> int:
- mp = collections.Counter()
+ mp = Counter()
mp[0] = 1
res = s = 0
for num in nums:
@@ -71,16 +70,17 @@ class Solution {
```ts
function subarraySum(nums: number[], k: number): number {
- let ans = 0, pre = 0;
- let hashTable = new Map();
- hashTable.set(0, 1);
- for (let num of nums) {
- pre += num;
- ans += (hashTable.get(pre - k) || 0);
- hashTable.set(pre, (hashTable.get(pre) || 0) + 1);
- }
- return ans;
-};
+ let ans = 0,
+ pre = 0;
+ let hashTable = new Map();
+ hashTable.set(0, 1);
+ for (let num of nums) {
+ pre += num;
+ ans += hashTable.get(pre - k) || 0;
+ hashTable.set(pre, (hashTable.get(pre) || 0) + 1);
+ }
+ return ans;
+}
```
### **C++**
diff --git a/solution/0500-0599/0560.Subarray Sum Equals K/README_EN.md b/solution/0500-0599/0560.Subarray Sum Equals K/README_EN.md
index b9a82df1cff1c..703e708310de2 100644
--- a/solution/0500-0599/0560.Subarray Sum Equals K/README_EN.md
+++ b/solution/0500-0599/0560.Subarray Sum Equals K/README_EN.md
@@ -23,7 +23,6 @@
-107 <= k <= 107
-
## Solutions
@@ -33,7 +32,7 @@
```python
class Solution:
def subarraySum(self, nums: List[int], k: int) -> int:
- mp = collections.Counter()
+ mp = Counter()
mp[0] = 1
res = s = 0
for num in nums:
@@ -66,16 +65,17 @@ class Solution {
```ts
function subarraySum(nums: number[], k: number): number {
- let ans = 0, pre = 0;
- let hashTable = new Map();
- hashTable.set(0, 1);
- for (let num of nums) {
- pre += num;
- ans += (hashTable.get(pre - k) || 0);
- hashTable.set(pre, (hashTable.get(pre) || 0) + 1);
- }
- return ans;
-};
+ let ans = 0,
+ pre = 0;
+ let hashTable = new Map();
+ hashTable.set(0, 1);
+ for (let num of nums) {
+ pre += num;
+ ans += hashTable.get(pre - k) || 0;
+ hashTable.set(pre, (hashTable.get(pre) || 0) + 1);
+ }
+ return ans;
+}
```
### **C++**
diff --git a/solution/0500-0599/0560.Subarray Sum Equals K/Solution.py b/solution/0500-0599/0560.Subarray Sum Equals K/Solution.py
index d46c68ee1ebb8..67aff52cf4fe9 100644
--- a/solution/0500-0599/0560.Subarray Sum Equals K/Solution.py
+++ b/solution/0500-0599/0560.Subarray Sum Equals K/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def subarraySum(self, nums: List[int], k: int) -> int:
- mp = collections.Counter()
+ mp = Counter()
mp[0] = 1
res = s = 0
for num in nums:
diff --git a/solution/0600-0699/0637.Average of Levels in Binary Tree/README.md b/solution/0600-0699/0637.Average of Levels in Binary Tree/README.md
index 29364003d0bfb..42a877d959f2a 100644
--- a/solution/0600-0699/0637.Average of Levels in Binary Tree/README.md
+++ b/solution/0600-0699/0637.Average of Levels in Binary Tree/README.md
@@ -31,7 +31,6 @@
节点值的范围在32位有符号整数范围内。
-
## 解法
@@ -52,7 +51,7 @@
class Solution:
def averageOfLevels(self, root: TreeNode) -> List[float]:
res = []
- q = collections.deque([root])
+ q = deque([root])
while q:
n = len(q)
s = 0
@@ -126,25 +125,25 @@ class Solution {
* @param {TreeNode} root
* @return {number[]}
*/
-var averageOfLevels = function(root) {
- let res = [];
- let queue = [root];
- while (queue.length > 0) {
- n = queue.length;
- let sum = 0;
- for (let i = 0; i < n; i++) {
- let node = queue.shift();
- sum += node.val;
- if (node.left) {
- queue.push(node.left);
- }
- if (node.right) {
- queue.push(node.right);
- }
- }
- res.push(sum / n);
+var averageOfLevels = function (root) {
+ let res = [];
+ let queue = [root];
+ while (queue.length > 0) {
+ n = queue.length;
+ let sum = 0;
+ for (let i = 0; i < n; i++) {
+ let node = queue.shift();
+ sum += node.val;
+ if (node.left) {
+ queue.push(node.left);
+ }
+ if (node.right) {
+ queue.push(node.right);
+ }
}
- return res;
+ res.push(sum / n);
+ }
+ return res;
};
```
diff --git a/solution/0600-0699/0637.Average of Levels in Binary Tree/README_EN.md b/solution/0600-0699/0637.Average of Levels in Binary Tree/README_EN.md
index d36e9889de5e2..e2d7b5670bdaa 100644
--- a/solution/0600-0699/0637.Average of Levels in Binary Tree/README_EN.md
+++ b/solution/0600-0699/0637.Average of Levels in Binary Tree/README_EN.md
@@ -5,6 +5,7 @@
## Description
Given the root
of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10-5
of the actual answer will be accepted.
+
Example 1:
@@ -30,7 +31,6 @@ Hence return [3, 14.5, 11].
-231 <= Node.val <= 231 - 1
-
## Solutions
@@ -47,7 +47,7 @@ Hence return [3, 14.5, 11].
class Solution:
def averageOfLevels(self, root: TreeNode) -> List[float]:
res = []
- q = collections.deque([root])
+ q = deque([root])
while q:
n = len(q)
s = 0
@@ -119,25 +119,25 @@ class Solution {
* @param {TreeNode} root
* @return {number[]}
*/
-var averageOfLevels = function(root) {
- let res = [];
- let queue = [root];
- while (queue.length > 0) {
- n = queue.length;
- let sum = 0;
- for (let i = 0; i < n; i++) {
- let node = queue.shift();
- sum += node.val;
- if (node.left) {
- queue.push(node.left);
- }
- if (node.right) {
- queue.push(node.right);
- }
- }
- res.push(sum / n);
+var averageOfLevels = function (root) {
+ let res = [];
+ let queue = [root];
+ while (queue.length > 0) {
+ n = queue.length;
+ let sum = 0;
+ for (let i = 0; i < n; i++) {
+ let node = queue.shift();
+ sum += node.val;
+ if (node.left) {
+ queue.push(node.left);
+ }
+ if (node.right) {
+ queue.push(node.right);
+ }
}
- return res;
+ res.push(sum / n);
+ }
+ return res;
};
```
diff --git a/solution/0600-0699/0637.Average of Levels in Binary Tree/Solution.py b/solution/0600-0699/0637.Average of Levels in Binary Tree/Solution.py
index 685572f80755b..af9367014d64b 100644
--- a/solution/0600-0699/0637.Average of Levels in Binary Tree/Solution.py
+++ b/solution/0600-0699/0637.Average of Levels in Binary Tree/Solution.py
@@ -7,7 +7,7 @@
class Solution:
def averageOfLevels(self, root: TreeNode) -> List[float]:
res = []
- q = collections.deque([root])
+ q = deque([root])
while q:
n = len(q)
s = 0
diff --git a/solution/0600-0699/0676.Implement Magic Dictionary/README.md b/solution/0600-0699/0676.Implement Magic Dictionary/README.md
index 0f5da3342bc58..6ab6f6d78a28c 100644
--- a/solution/0600-0699/0676.Implement Magic Dictionary/README.md
+++ b/solution/0600-0699/0676.Implement Magic Dictionary/README.md
@@ -82,7 +82,7 @@ class MagicDictionary:
def buildDict(self, dictionary: List[str]) -> None:
self.words = set(dictionary)
- self.counter = collections.Counter(
+ self.counter = Counter(
p for word in dictionary for p in self._patterns(word))
def search(self, searchWord: str) -> bool:
diff --git a/solution/0600-0699/0676.Implement Magic Dictionary/README_EN.md b/solution/0600-0699/0676.Implement Magic Dictionary/README_EN.md
index d4a31393dc775..dfba29a481a53 100644
--- a/solution/0600-0699/0676.Implement Magic Dictionary/README_EN.md
+++ b/solution/0600-0699/0676.Implement Magic Dictionary/README_EN.md
@@ -66,7 +66,7 @@ class MagicDictionary:
def buildDict(self, dictionary: List[str]) -> None:
self.words = set(dictionary)
- self.counter = collections.Counter(
+ self.counter = Counter(
p for word in dictionary for p in self._patterns(word))
def search(self, searchWord: str) -> bool:
diff --git a/solution/0600-0699/0676.Implement Magic Dictionary/Solution.py b/solution/0600-0699/0676.Implement Magic Dictionary/Solution.py
index 282726c1c88dd..c37bb9f8a5707 100644
--- a/solution/0600-0699/0676.Implement Magic Dictionary/Solution.py
+++ b/solution/0600-0699/0676.Implement Magic Dictionary/Solution.py
@@ -10,7 +10,7 @@ def _patterns(self, word):
def buildDict(self, dictionary: List[str]) -> None:
self.words = set(dictionary)
- self.counter = collections.Counter(
+ self.counter = Counter(
p for word in dictionary for p in self._patterns(word))
def search(self, searchWord: str) -> bool:
diff --git a/solution/0600-0699/0677.Map Sum Pairs/README.md b/solution/0600-0699/0677.Map Sum Pairs/README.md
index 5a316455b0abe..3d74820395096 100644
--- a/solution/0600-0699/0677.Map Sum Pairs/README.md
+++ b/solution/0600-0699/0677.Map Sum Pairs/README.md
@@ -63,8 +63,8 @@ class MapSum:
"""
Initialize your data structure here.
"""
- self.data = collections.defaultdict(int)
- self.t = collections.defaultdict(int)
+ self.data = defaultdict(int)
+ self.t = defaultdict(int)
def insert(self, key: str, val: int) -> None:
old = self.t[key]
diff --git a/solution/0600-0699/0677.Map Sum Pairs/README_EN.md b/solution/0600-0699/0677.Map Sum Pairs/README_EN.md
index c10c02e44848d..3f33577726c05 100644
--- a/solution/0600-0699/0677.Map Sum Pairs/README_EN.md
+++ b/solution/0600-0699/0677.Map Sum Pairs/README_EN.md
@@ -53,8 +53,8 @@ class MapSum:
"""
Initialize your data structure here.
"""
- self.data = collections.defaultdict(int)
- self.t = collections.defaultdict(int)
+ self.data = defaultdict(int)
+ self.t = defaultdict(int)
def insert(self, key: str, val: int) -> None:
old = self.t[key]
@@ -84,7 +84,7 @@ class MapSum {
data = new HashMap<>();
t = new HashMap<>();
}
-
+
public void insert(String key, int val) {
int old = t.getOrDefault(key, 0);
t.put(key, val);
@@ -93,7 +93,7 @@ class MapSum {
data.put(k, data.getOrDefault(k, 0) + (val - old));
}
}
-
+
public int sum(String prefix) {
return data.getOrDefault(prefix, 0);
}
diff --git a/solution/0600-0699/0677.Map Sum Pairs/Solution.py b/solution/0600-0699/0677.Map Sum Pairs/Solution.py
index 458a397171292..b4a8b14b1b32a 100644
--- a/solution/0600-0699/0677.Map Sum Pairs/Solution.py
+++ b/solution/0600-0699/0677.Map Sum Pairs/Solution.py
@@ -4,8 +4,8 @@ def __init__(self):
"""
Initialize your data structure here.
"""
- self.data = collections.defaultdict(int)
- self.t = collections.defaultdict(int)
+ self.data = defaultdict(int)
+ self.t = defaultdict(int)
def insert(self, key: str, val: int) -> None:
old = self.t[key]
@@ -20,4 +20,4 @@ def sum(self, prefix: str) -> int:
# Your MapSum object will be instantiated and called as such:
# obj = MapSum()
# obj.insert(key,val)
-# param_2 = obj.sum(prefix)
\ No newline at end of file
+# param_2 = obj.sum(prefix)
diff --git a/solution/0600-0699/0692.Top K Frequent Words/README.md b/solution/0600-0699/0692.Top K Frequent Words/README.md
index 53b68ce89a3bc..31d1464a81d71 100644
--- a/solution/0600-0699/0692.Top K Frequent Words/README.md
+++ b/solution/0600-0699/0692.Top K Frequent Words/README.md
@@ -60,7 +60,7 @@
```python
class Solution:
def topKFrequent(self, words: List[str], k: int) -> List[str]:
- counter = collections.Counter(words)
+ counter = Counter(words)
res = sorted(counter, key=lambda word: (-counter[word], word))
return res[:k]
```
diff --git a/solution/0600-0699/0692.Top K Frequent Words/README_EN.md b/solution/0600-0699/0692.Top K Frequent Words/README_EN.md
index 4f7be35bc8dc8..462046219523c 100644
--- a/solution/0600-0699/0692.Top K Frequent Words/README_EN.md
+++ b/solution/0600-0699/0692.Top K Frequent Words/README_EN.md
@@ -71,7 +71,7 @@
```python
class Solution:
def topKFrequent(self, words: List[str], k: int) -> List[str]:
- counter = collections.Counter(words)
+ counter = Counter(words)
res = sorted(counter, key=lambda word: (-counter[word], word))
return res[:k]
```
diff --git a/solution/0600-0699/0692.Top K Frequent Words/Solution.py b/solution/0600-0699/0692.Top K Frequent Words/Solution.py
index 49b7e133d081a..21b10376a60c9 100644
--- a/solution/0600-0699/0692.Top K Frequent Words/Solution.py
+++ b/solution/0600-0699/0692.Top K Frequent Words/Solution.py
@@ -1,5 +1,5 @@
class Solution:
def topKFrequent(self, words: List[str], k: int) -> List[str]:
- counter = collections.Counter(words)
+ counter = Counter(words)
res = sorted(counter, key=lambda word: (-counter[word], word))
return res[:k]
diff --git a/solution/0700-0799/0721.Accounts Merge/README.md b/solution/0700-0799/0721.Accounts Merge/README.md
index 530b31b22e00a..7df07868c9984 100644
--- a/solution/0700-0799/0721.Accounts Merge/README.md
+++ b/solution/0700-0799/0721.Accounts Merge/README.md
@@ -131,7 +131,7 @@ class Solution:
else:
email_id[email] = i
- mp = collections.defaultdict(set)
+ mp = defaultdict(set)
for i in range(n):
pa = find(i)
for email in accounts[i][1:]:
diff --git a/solution/0700-0799/0721.Accounts Merge/README_EN.md b/solution/0700-0799/0721.Accounts Merge/README_EN.md
index a1fca3319e997..e59872980f8bd 100644
--- a/solution/0700-0799/0721.Accounts Merge/README_EN.md
+++ b/solution/0700-0799/0721.Accounts Merge/README_EN.md
@@ -67,7 +67,7 @@ class Solution:
else:
email_id[email] = i
- mp = collections.defaultdict(set)
+ mp = defaultdict(set)
for i in range(n):
pa = find(i)
for email in accounts[i][1:]:
diff --git a/solution/0700-0799/0721.Accounts Merge/Solution.py b/solution/0700-0799/0721.Accounts Merge/Solution.py
index c05b0f88dd686..0a87a38d3c691 100644
--- a/solution/0700-0799/0721.Accounts Merge/Solution.py
+++ b/solution/0700-0799/0721.Accounts Merge/Solution.py
@@ -17,7 +17,7 @@ def find(x):
else:
email_id[email] = i
- mp = collections.defaultdict(set)
+ mp = defaultdict(set)
for i in range(n):
pa = find(i)
for email in accounts[i][1:]:
diff --git a/solution/0700-0799/0760.Find Anagram Mappings/README.md b/solution/0700-0799/0760.Find Anagram Mappings/README.md
index 21ac432b6c28f..2455a5d2f1c49 100644
--- a/solution/0700-0799/0760.Find Anagram Mappings/README.md
+++ b/solution/0700-0799/0760.Find Anagram Mappings/README.md
@@ -38,7 +38,6 @@ B = [50, 12, 32, 46, 28]
-
## 解法
@@ -52,7 +51,7 @@ B = [50, 12, 32, 46, 28]
```python
class Solution:
def anagramMappings(self, nums1: List[int], nums2: List[int]) -> List[int]:
- mapper = collections.defaultdict(set)
+ mapper = defaultdict(set)
for i, num in enumerate(nums2):
mapper[num].add(i)
return [mapper[num].pop() for num in nums1]
diff --git a/solution/0700-0799/0760.Find Anagram Mappings/README_EN.md b/solution/0700-0799/0760.Find Anagram Mappings/README_EN.md
index abeaf324300d6..d88ee08e84b52 100644
--- a/solution/0700-0799/0760.Find Anagram Mappings/README_EN.md
+++ b/solution/0700-0799/0760.Find Anagram Mappings/README_EN.md
@@ -65,7 +65,7 @@ and so on.
```python
class Solution:
def anagramMappings(self, nums1: List[int], nums2: List[int]) -> List[int]:
- mapper = collections.defaultdict(set)
+ mapper = defaultdict(set)
for i, num in enumerate(nums2):
mapper[num].add(i)
return [mapper[num].pop() for num in nums1]
diff --git a/solution/0700-0799/0760.Find Anagram Mappings/Solution.py b/solution/0700-0799/0760.Find Anagram Mappings/Solution.py
index 47888445419fb..515418ea7a56d 100644
--- a/solution/0700-0799/0760.Find Anagram Mappings/Solution.py
+++ b/solution/0700-0799/0760.Find Anagram Mappings/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def anagramMappings(self, nums1: List[int], nums2: List[int]) -> List[int]:
- mapper = collections.defaultdict(set)
+ mapper = defaultdict(set)
for i, num in enumerate(nums2):
mapper[num].add(i)
return [mapper[num].pop() for num in nums1]
diff --git a/solution/0700-0799/0763.Partition Labels/README.md b/solution/0700-0799/0763.Partition Labels/README.md
index 397f34e7d14e3..2203393ca9cf1 100644
--- a/solution/0700-0799/0763.Partition Labels/README.md
+++ b/solution/0700-0799/0763.Partition Labels/README.md
@@ -43,7 +43,7 @@
```python
class Solution:
def partitionLabels(self, s: str) -> List[int]:
- last = collections.defaultdict(int)
+ last = defaultdict(int)
n = len(s)
for i in range(n):
last[s[i]] = i
@@ -86,22 +86,23 @@ class Solution {
```ts
function partitionLabels(s: string): number[] {
- const n = s.length;
- let last = new Array(128);
- for (let i = 0; i < n; i++) {
- last[s.charCodeAt(i)] = i;
+ const n = s.length;
+ let last = new Array(128);
+ for (let i = 0; i < n; i++) {
+ last[s.charCodeAt(i)] = i;
+ }
+ let ans = [];
+ let left = 0,
+ right = 0;
+ for (let i = 0; i < n; i++) {
+ right = Math.max(right, last[s.charCodeAt(i)]);
+ if (i == right) {
+ ans.push(right - left + 1);
+ left = right + 1;
}
- let ans = [];
- let left = 0, right = 0;
- for (let i = 0; i < n; i++) {
- right = Math.max(right, last[s.charCodeAt(i)]);
- if (i == right) {
- ans.push(right - left + 1);
- left = right + 1;
- }
- }
- return ans;
-};
+ }
+ return ans;
+}
```
### **C++**
diff --git a/solution/0700-0799/0763.Partition Labels/README_EN.md b/solution/0700-0799/0763.Partition Labels/README_EN.md
index 53baa3a7c73b2..4a4b4bbbcecdc 100644
--- a/solution/0700-0799/0763.Partition Labels/README_EN.md
+++ b/solution/0700-0799/0763.Partition Labels/README_EN.md
@@ -39,7 +39,7 @@ A partition like "ababcbacadefegde", "hijhklij" is incorrect
```python
class Solution:
def partitionLabels(self, s: str) -> List[int]:
- last = collections.defaultdict(int)
+ last = defaultdict(int)
n = len(s)
for i in range(n):
last[s[i]] = i
@@ -80,22 +80,23 @@ class Solution {
```ts
function partitionLabels(s: string): number[] {
- const n = s.length;
- let last = new Array(128);
- for (let i = 0; i < n; i++) {
- last[s.charCodeAt(i)] = i;
+ const n = s.length;
+ let last = new Array(128);
+ for (let i = 0; i < n; i++) {
+ last[s.charCodeAt(i)] = i;
+ }
+ let ans = [];
+ let left = 0,
+ right = 0;
+ for (let i = 0; i < n; i++) {
+ right = Math.max(right, last[s.charCodeAt(i)]);
+ if (i == right) {
+ ans.push(right - left + 1);
+ left = right + 1;
}
- let ans = [];
- let left = 0, right = 0;
- for (let i = 0; i < n; i++) {
- right = Math.max(right, last[s.charCodeAt(i)]);
- if (i == right) {
- ans.push(right - left + 1);
- left = right + 1;
- }
- }
- return ans;
-};
+ }
+ return ans;
+}
```
### **C++**
diff --git a/solution/0700-0799/0763.Partition Labels/Solution.py b/solution/0700-0799/0763.Partition Labels/Solution.py
index a63e8240b2cc5..f7a95bbbeaf33 100644
--- a/solution/0700-0799/0763.Partition Labels/Solution.py
+++ b/solution/0700-0799/0763.Partition Labels/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def partitionLabels(self, s: str) -> List[int]:
- last = collections.defaultdict(int)
+ last = defaultdict(int)
n = len(s)
for i in range(n):
last[s[i]] = i
diff --git a/solution/0700-0799/0781.Rabbits in Forest/README.md b/solution/0700-0799/0781.Rabbits in Forest/README.md
index 5ed2e6cf4cc31..69d7244c48fcb 100644
--- a/solution/0700-0799/0781.Rabbits in Forest/README.md
+++ b/solution/0700-0799/0781.Rabbits in Forest/README.md
@@ -35,7 +35,6 @@
answers[i]
是在 [0, 999]
范围内的整数。
-
## 解法
@@ -55,7 +54,7 @@
```python
class Solution:
def numRabbits(self, answers: List[int]) -> int:
- counter = collections.Counter(answers)
+ counter = Counter(answers)
return sum([math.ceil(v / (k + 1)) * (k + 1) for k, v in counter.items()])
```
diff --git a/solution/0700-0799/0781.Rabbits in Forest/README_EN.md b/solution/0700-0799/0781.Rabbits in Forest/README_EN.md
index c34b16a9c2d80..8af4e46630dba 100644
--- a/solution/0700-0799/0781.Rabbits in Forest/README_EN.md
+++ b/solution/0700-0799/0781.Rabbits in Forest/README_EN.md
@@ -6,12 +6,8 @@
In a forest, each rabbit has some color. Some subset of rabbits (possibly all of them) tell you how many other rabbits have the same color as them. Those answers
are placed in an array.
-
-
Return the minimum number of rabbits that could be in the forest.
-
-
Examples:
@@ -46,19 +42,13 @@ The smallest possible number of rabbits in the forest is therefore 5: 3 that ans
-
-
Note:
-
-
answers
will have length at most 1000
.
- Each
answers[i]
will be an integer in the range [0, 999]
.
-
-
## Solutions
@@ -68,7 +58,7 @@ The smallest possible number of rabbits in the forest is therefore 5: 3 that ans
```python
class Solution:
def numRabbits(self, answers: List[int]) -> int:
- counter = collections.Counter(answers)
+ counter = Counter(answers)
return sum([math.ceil(v / (k + 1)) * (k + 1) for k, v in counter.items()])
```
diff --git a/solution/0700-0799/0781.Rabbits in Forest/Solution.py b/solution/0700-0799/0781.Rabbits in Forest/Solution.py
index b13520783dfc1..9adfd9193eb15 100644
--- a/solution/0700-0799/0781.Rabbits in Forest/Solution.py
+++ b/solution/0700-0799/0781.Rabbits in Forest/Solution.py
@@ -1,4 +1,4 @@
class Solution:
def numRabbits(self, answers: List[int]) -> int:
- counter = collections.Counter(answers)
+ counter = Counter(answers)
return sum([math.ceil(v / (k + 1)) * (k + 1) for k, v in counter.items()])
diff --git a/solution/0700-0799/0792.Number of Matching Subsequences/README.md b/solution/0700-0799/0792.Number of Matching Subsequences/README.md
index 9d2b0a1e1a8c2..cff49686a6f74 100644
--- a/solution/0700-0799/0792.Number of Matching Subsequences/README.md
+++ b/solution/0700-0799/0792.Number of Matching Subsequences/README.md
@@ -54,7 +54,7 @@ buckets = {
```python
class Solution:
def numMatchingSubseq(self, s: str, words: List[str]) -> int:
- buckets = collections.defaultdict(list)
+ buckets = defaultdict(list)
for word in words:
buckets[word[0]].append(word)
res = 0
diff --git a/solution/0700-0799/0792.Number of Matching Subsequences/README_EN.md b/solution/0700-0799/0792.Number of Matching Subsequences/README_EN.md
index c39dbfbb9f795..57005e73702a6 100644
--- a/solution/0700-0799/0792.Number of Matching Subsequences/README_EN.md
+++ b/solution/0700-0799/0792.Number of Matching Subsequences/README_EN.md
@@ -47,7 +47,7 @@
```python
class Solution:
def numMatchingSubseq(self, s: str, words: List[str]) -> int:
- buckets = collections.defaultdict(list)
+ buckets = defaultdict(list)
for word in words:
buckets[word[0]].append(word)
res = 0
diff --git a/solution/0700-0799/0792.Number of Matching Subsequences/Solution.py b/solution/0700-0799/0792.Number of Matching Subsequences/Solution.py
index 6c728a4923d4a..1834f5d40ef14 100644
--- a/solution/0700-0799/0792.Number of Matching Subsequences/Solution.py
+++ b/solution/0700-0799/0792.Number of Matching Subsequences/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def numMatchingSubseq(self, s: str, words: List[str]) -> int:
- buckets = collections.defaultdict(list)
+ buckets = defaultdict(list)
for word in words:
buckets[word[0]].append(word)
res = 0
diff --git a/solution/0800-0899/0811.Subdomain Visit Count/README.md b/solution/0800-0899/0811.Subdomain Visit Count/README.md
index cec347c9b2733..4b9c5ed650adf 100644
--- a/solution/0800-0899/0811.Subdomain Visit Count/README.md
+++ b/solution/0800-0899/0811.Subdomain Visit Count/README.md
@@ -42,7 +42,6 @@
输入中任意一个域名的访问次数都小于10000
。
-
## 解法
@@ -56,7 +55,7 @@
```python
class Solution:
def subdomainVisits(self, cpdomains: List[str]) -> List[str]:
- domains = collections.Counter()
+ domains = Counter()
for item in cpdomains:
count, domain = item.split()
count = int(count)
diff --git a/solution/0800-0899/0811.Subdomain Visit Count/README_EN.md b/solution/0800-0899/0811.Subdomain Visit Count/README_EN.md
index 57eedf09641e0..083471e754b8a 100644
--- a/solution/0800-0899/0811.Subdomain Visit Count/README_EN.md
+++ b/solution/0800-0899/0811.Subdomain Visit Count/README_EN.md
@@ -6,16 +6,10 @@
A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com", and at the lowest level, "discuss.leetcode.com". When we visit a domain like "discuss.leetcode.com", we will also visit the parent domains "leetcode.com" and "com" implicitly.
-
-
Now, call a "count-paired domain" to be a count (representing the number of visits this domain received), followed by a space, followed by the address. An example of a count-paired domain might be "9001 discuss.leetcode.com".
-
-
We are given a list cpdomains
of count-paired domains. We would like a list of count-paired domains, (in the same format as the input, and in any order), that explicitly counts the number of visits to each subdomain.
-
-
Example 1:
@@ -36,8 +30,6 @@ We only have one website domain: "discuss.leetcode.com". As discussed
-
-
Example 2:
@@ -58,12 +50,8 @@ We will visit "google.mail.com" 900 times, "yahoo.com" 50 ti
-
-
Notes:
-
-
- The length of
cpdomains
will not exceed 100
.
- The length of each domain name will not exceed
100
.
@@ -72,8 +60,6 @@ We will visit "google.mail.com" 900 times, "yahoo.com" 50 ti
- The answer output can be returned in any order.
-
-
## Solutions
@@ -83,7 +69,7 @@ We will visit "google.mail.com" 900 times, "yahoo.com" 50 ti
```python
class Solution:
def subdomainVisits(self, cpdomains: List[str]) -> List[str]:
- domains = collections.Counter()
+ domains = Counter()
for item in cpdomains:
count, domain = item.split()
count = int(count)
diff --git a/solution/0800-0899/0811.Subdomain Visit Count/Solution.py b/solution/0800-0899/0811.Subdomain Visit Count/Solution.py
index 22063cfa85b10..a535accd0b576 100644
--- a/solution/0800-0899/0811.Subdomain Visit Count/Solution.py
+++ b/solution/0800-0899/0811.Subdomain Visit Count/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def subdomainVisits(self, cpdomains: List[str]) -> List[str]:
- domains = collections.Counter()
+ domains = Counter()
for item in cpdomains:
count, domain = item.split()
count = int(count)
diff --git a/solution/0800-0899/0819.Most Common Word/README.md b/solution/0800-0899/0819.Most Common Word/README.md
index f6a9d829327f0..887cb6f5727ac 100644
--- a/solution/0800-0899/0819.Most Common Word/README.md
+++ b/solution/0800-0899/0819.Most Common Word/README.md
@@ -56,7 +56,7 @@ banned = ["hit"]
```python
class Solution:
def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:
- paragraph = collections.Counter(re.findall('[a-z]+', paragraph.lower()))
+ paragraph = Counter(re.findall('[a-z]+', paragraph.lower()))
banned_words = set(banned)
for word, _ in paragraph.most_common():
if word not in banned_words:
diff --git a/solution/0800-0899/0819.Most Common Word/README_EN.md b/solution/0800-0899/0819.Most Common Word/README_EN.md
index 95730eb0ebe24..2f401b2f6ac07 100644
--- a/solution/0800-0899/0819.Most Common Word/README_EN.md
+++ b/solution/0800-0899/0819.Most Common Word/README_EN.md
@@ -49,7 +49,7 @@ and that "hit" isn't the answer even though it occurs more because
```python
class Solution:
def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:
- paragraph = collections.Counter(re.findall('[a-z]+', paragraph.lower()))
+ paragraph = Counter(re.findall('[a-z]+', paragraph.lower()))
banned_words = set(banned)
for word, _ in paragraph.most_common():
if word not in banned_words:
diff --git a/solution/0800-0899/0819.Most Common Word/Solution.py b/solution/0800-0899/0819.Most Common Word/Solution.py
index 07fdea9925b11..c3fa6036051f1 100644
--- a/solution/0800-0899/0819.Most Common Word/Solution.py
+++ b/solution/0800-0899/0819.Most Common Word/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:
- paragraph = collections.Counter(re.findall('[a-z]+', paragraph.lower()))
+ paragraph = Counter(re.findall('[a-z]+', paragraph.lower()))
banned_words = set(banned)
for word, _ in paragraph.most_common():
if word not in banned_words:
diff --git a/solution/0800-0899/0886.Possible Bipartition/README.md b/solution/0800-0899/0886.Possible Bipartition/README.md
index f4d41c1f40979..a64a3812d7d06 100644
--- a/solution/0800-0899/0886.Possible Bipartition/README.md
+++ b/solution/0800-0899/0886.Possible Bipartition/README.md
@@ -99,6 +99,7 @@ if find(a) != find(b):
模板 3——维护到祖宗节点距离的并查集:
x
+
```python
# 初始化,p存储每个点的父节点,d[x]存储x到p[x]的距离
p = list(range(n))
@@ -133,7 +134,7 @@ class Solution:
p[x] = find(p[x])
return p[x]
- mp = collections.defaultdict(list)
+ mp = defaultdict(list)
for i, j in dislikes:
mp[i - 1].append(j - 1)
mp[j - 1].append(i - 1)
diff --git a/solution/0800-0899/0886.Possible Bipartition/README_EN.md b/solution/0800-0899/0886.Possible Bipartition/README_EN.md
index e9637b98ca063..9ac45bbd0c798 100644
--- a/solution/0800-0899/0886.Possible Bipartition/README_EN.md
+++ b/solution/0800-0899/0886.Possible Bipartition/README_EN.md
@@ -101,7 +101,7 @@ class Solution:
p[x] = find(p[x])
return p[x]
- mp = collections.defaultdict(list)
+ mp = defaultdict(list)
for i, j in dislikes:
mp[i - 1].append(j - 1)
mp[j - 1].append(i - 1)
diff --git a/solution/0800-0899/0886.Possible Bipartition/Solution.py b/solution/0800-0899/0886.Possible Bipartition/Solution.py
index d61b6b1606a31..d1d0f4e111b51 100644
--- a/solution/0800-0899/0886.Possible Bipartition/Solution.py
+++ b/solution/0800-0899/0886.Possible Bipartition/Solution.py
@@ -6,8 +6,8 @@ def find(x):
if p[x] != x:
p[x] = find(p[x])
return p[x]
-
- mp = collections.defaultdict(list)
+
+ mp = defaultdict(list)
for i, j in dislikes:
mp[i - 1].append(j - 1)
mp[j - 1].append(i - 1)
diff --git a/solution/0900-0999/0904.Fruit Into Baskets/README.md b/solution/0900-0999/0904.Fruit Into Baskets/README.md
index 2465becdeb0f4..3b44ae641df0c 100644
--- a/solution/0900-0999/0904.Fruit Into Baskets/README.md
+++ b/solution/0900-0999/0904.Fruit Into Baskets/README.md
@@ -62,7 +62,6 @@
0 <= tree[i] < tree.length
-
## 解法
@@ -78,7 +77,7 @@
```python
class Solution:
def totalFruit(self, tree: List[int]) -> int:
- counter = collections.Counter()
+ counter = Counter()
i = res = 0
for j, type in enumerate(tree):
counter[type] += 1
diff --git a/solution/0900-0999/0904.Fruit Into Baskets/README_EN.md b/solution/0900-0999/0904.Fruit Into Baskets/README_EN.md
index c89d7029bbc09..6f3f27ac912b1 100644
--- a/solution/0900-0999/0904.Fruit Into Baskets/README_EN.md
+++ b/solution/0900-0999/0904.Fruit Into Baskets/README_EN.md
@@ -6,39 +6,23 @@
In a row of trees, the i
-th tree produces fruit with type tree[i]
.
-
-
You start at any tree of your choice, then repeatedly perform the following steps:
-
-
- Add one piece of fruit from this tree to your baskets. If you cannot, stop.
- Move to the next tree to the right of the current tree. If there is no tree to the right, stop.
-
-
Note that you do not have any choice after the initial choice of starting tree: you must perform step 1, then step 2, then back to step 1, then step 2, and so on until you stop.
-
-
You have two baskets, and each basket can carry any quantity of fruit, but you want each basket to only carry one type of fruit each.
-
-
What is the total amount of fruit you can collect with this procedure?
-
-
-
-
Example 1:
-
-
Input: [1,2,1]
@@ -49,14 +33,10 @@
-
-
Example 2:
-
-
Input: [0,1,2,2]
@@ -69,14 +49,10 @@ If we started at the first tree, we would only collect [0, 1].
-
-
Example 3:
-
-
Input: [1,2,3,2,2]
@@ -89,14 +65,10 @@ If we started at the first tree, we would only collect [0, 1].
-
-
Example 4:
-
-
Input: [3,3,3,1,2,1,1,2,3,3,4]
@@ -109,8 +81,6 @@ If we started at the first tree, we would only collect [0, 1].
-
-
@@ -119,19 +89,13 @@ If we started at the first tree, we would only collect [0, 1].
-
-
Note:
-
-
1 <= tree.length <= 40000
0 <= tree[i] < tree.length
-
-
## Solutions
@@ -141,7 +105,7 @@ If we started at the first tree, we would only collect [0, 1].
```python
class Solution:
def totalFruit(self, tree: List[int]) -> int:
- counter = collections.Counter()
+ counter = Counter()
i = res = 0
for j, type in enumerate(tree):
counter[type] += 1
diff --git a/solution/0900-0999/0904.Fruit Into Baskets/Solution.py b/solution/0900-0999/0904.Fruit Into Baskets/Solution.py
index a29c0664c7fe4..bb4e12c27201b 100644
--- a/solution/0900-0999/0904.Fruit Into Baskets/Solution.py
+++ b/solution/0900-0999/0904.Fruit Into Baskets/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def totalFruit(self, tree: List[int]) -> int:
- counter = collections.Counter()
+ counter = Counter()
i = res = 0
for j, type in enumerate(tree):
counter[type] += 1
diff --git a/solution/0900-0999/0919.Complete Binary Tree Inserter/README.md b/solution/0900-0999/0919.Complete Binary Tree Inserter/README.md
index e3a565405aab3..27be8e77e1875 100644
--- a/solution/0900-0999/0919.Complete Binary Tree Inserter/README.md
+++ b/solution/0900-0999/0919.Complete Binary Tree Inserter/README.md
@@ -64,7 +64,7 @@ class CBTInserter:
def __init__(self, root: TreeNode):
self.tree = []
- q = collections.deque([root])
+ q = deque([root])
while q:
n = len(q)
for _ in range(n):
diff --git a/solution/0900-0999/0919.Complete Binary Tree Inserter/README_EN.md b/solution/0900-0999/0919.Complete Binary Tree Inserter/README_EN.md
index dc1f14a98177e..2578c60160a8e 100644
--- a/solution/0900-0999/0919.Complete Binary Tree Inserter/README_EN.md
+++ b/solution/0900-0999/0919.Complete Binary Tree Inserter/README_EN.md
@@ -85,7 +85,7 @@ class CBTInserter:
def __init__(self, root: TreeNode):
self.tree = []
- q = collections.deque([root])
+ q = deque([root])
while q:
n = len(q)
for _ in range(n):
diff --git a/solution/0900-0999/0919.Complete Binary Tree Inserter/Solution.py b/solution/0900-0999/0919.Complete Binary Tree Inserter/Solution.py
index c35288cb8761d..8f93893d8a904 100644
--- a/solution/0900-0999/0919.Complete Binary Tree Inserter/Solution.py
+++ b/solution/0900-0999/0919.Complete Binary Tree Inserter/Solution.py
@@ -8,7 +8,7 @@ class CBTInserter:
def __init__(self, root: TreeNode):
self.tree = []
- q = collections.deque([root])
+ q = deque([root])
while q:
n = len(q)
for _ in range(n):
@@ -36,4 +36,4 @@ def get_root(self) -> TreeNode:
# Your CBTInserter object will be instantiated and called as such:
# obj = CBTInserter(root)
# param_1 = obj.insert(val)
-# param_2 = obj.get_root()
\ No newline at end of file
+# param_2 = obj.get_root()
diff --git a/solution/0900-0999/0928.Minimize Malware Spread II/README.md b/solution/0900-0999/0928.Minimize Malware Spread II/README.md
index b7acb2241dee3..f333b4345fc57 100644
--- a/solution/0900-0999/0928.Minimize Malware Spread II/README.md
+++ b/solution/0900-0999/0928.Minimize Malware Spread II/README.md
@@ -155,7 +155,7 @@ class Solution:
p[pa] = pb
size[pb] += size[pa]
- cnt = collections.Counter()
+ cnt = Counter()
mp = {}
for i in initial:
s = set()
diff --git a/solution/0900-0999/0928.Minimize Malware Spread II/README_EN.md b/solution/0900-0999/0928.Minimize Malware Spread II/README_EN.md
index 0263c8ddee715..c9466360b3cb3 100644
--- a/solution/0900-0999/0928.Minimize Malware Spread II/README_EN.md
+++ b/solution/0900-0999/0928.Minimize Malware Spread II/README_EN.md
@@ -75,7 +75,7 @@ class Solution:
p[pa] = pb
size[pb] += size[pa]
- cnt = collections.Counter()
+ cnt = Counter()
mp = {}
for i in initial:
s = set()
diff --git a/solution/0900-0999/0928.Minimize Malware Spread II/Solution.py b/solution/0900-0999/0928.Minimize Malware Spread II/Solution.py
index 42a341c5fa4fa..c651bdbb24ef9 100644
--- a/solution/0900-0999/0928.Minimize Malware Spread II/Solution.py
+++ b/solution/0900-0999/0928.Minimize Malware Spread II/Solution.py
@@ -26,7 +26,7 @@ def find(x):
p[pa] = pb
size[pb] += size[pa]
- cnt = collections.Counter()
+ cnt = Counter()
mp = {}
for i in initial:
s = set()
diff --git a/solution/0900-0999/0933.Number of Recent Calls/README.md b/solution/0900-0999/0933.Number of Recent Calls/README.md
index dcc6facd8b8cd..183fc30738cd3 100644
--- a/solution/0900-0999/0933.Number of Recent Calls/README.md
+++ b/solution/0900-0999/0933.Number of Recent Calls/README.md
@@ -64,7 +64,7 @@ recentCounter.ping(3002); // requests = [1,
100,
3001<
class RecentCounter:
def __init__(self):
- self.q = collections.deque()
+ self.q = deque()
def ping(self, t: int) -> int:
self.q.append(t)
@@ -89,7 +89,7 @@ class RecentCounter {
public RecentCounter() {
q = new LinkedList<>();
}
-
+
public int ping(int t) {
q.offerLast(t);
while (q.peekFirst() < t - 3000) {
@@ -116,7 +116,7 @@ public:
RecentCounter() {
}
-
+
int ping(int t) {
q.push_back(t);
while (q.front() < t - 3000) {
@@ -164,20 +164,20 @@ func (this *RecentCounter) Ping(t int) int {
### **JavaScript**
```js
-var RecentCounter = function() {
- this.q = [];
+var RecentCounter = function () {
+ this.q = [];
};
-/**
+/**
* @param {number} t
* @return {number}
*/
-RecentCounter.prototype.ping = function(t) {
- this.q.push(t);
- while (this.q[0] < t - 3000) {
- this.q.shift();
- }
- return this.q.length;
+RecentCounter.prototype.ping = function (t) {
+ this.q.push(t);
+ while (this.q[0] < t - 3000) {
+ this.q.shift();
+ }
+ return this.q.length;
};
/**
diff --git a/solution/0900-0999/0933.Number of Recent Calls/README_EN.md b/solution/0900-0999/0933.Number of Recent Calls/README_EN.md
index 993b1107d2487..cd95186f5d1c3 100644
--- a/solution/0900-0999/0933.Number of Recent Calls/README_EN.md
+++ b/solution/0900-0999/0933.Number of Recent Calls/README_EN.md
@@ -52,7 +52,7 @@ recentCounter.ping(3002); // requests = [1, 100, 3001, 3002 int:
self.q.append(t)
@@ -75,7 +75,7 @@ class RecentCounter {
public RecentCounter() {
q = new LinkedList<>();
}
-
+
public int ping(int t) {
q.offerLast(t);
while (q.peekFirst() < t - 3000) {
@@ -102,7 +102,7 @@ public:
RecentCounter() {
}
-
+
int ping(int t) {
q.push_back(t);
while (q.front() < t - 3000) {
@@ -150,20 +150,20 @@ func (this *RecentCounter) Ping(t int) int {
### **JavaScript**
```js
-var RecentCounter = function() {
- this.q = [];
+var RecentCounter = function () {
+ this.q = [];
};
-/**
+/**
* @param {number} t
* @return {number}
*/
-RecentCounter.prototype.ping = function(t) {
- this.q.push(t);
- while (this.q[0] < t - 3000) {
- this.q.shift();
- }
- return this.q.length;
+RecentCounter.prototype.ping = function (t) {
+ this.q.push(t);
+ while (this.q[0] < t - 3000) {
+ this.q.shift();
+ }
+ return this.q.length;
};
/**
diff --git a/solution/0900-0999/0933.Number of Recent Calls/Solution.py b/solution/0900-0999/0933.Number of Recent Calls/Solution.py
index 9c7d308401f2f..21fe7a59b334b 100644
--- a/solution/0900-0999/0933.Number of Recent Calls/Solution.py
+++ b/solution/0900-0999/0933.Number of Recent Calls/Solution.py
@@ -1,7 +1,7 @@
class RecentCounter:
def __init__(self):
- self.q = collections.deque()
+ self.q = deque()
def ping(self, t: int) -> int:
self.q.append(t)
@@ -12,4 +12,4 @@ def ping(self, t: int) -> int:
# Your RecentCounter object will be instantiated and called as such:
# obj = RecentCounter()
-# param_1 = obj.ping(t)
\ No newline at end of file
+# param_1 = obj.ping(t)
diff --git a/solution/0900-0999/0981.Time Based Key-Value Store/README.md b/solution/0900-0999/0981.Time Based Key-Value Store/README.md
index c51020967e40b..41b72e99aeef6 100644
--- a/solution/0900-0999/0981.Time Based Key-Value Store/README.md
+++ b/solution/0900-0999/0981.Time Based Key-Value Store/README.md
@@ -76,7 +76,7 @@ class TimeMap:
"""
Initialize your data structure here.
"""
- self.ktv = collections.defaultdict(list)
+ self.ktv = defaultdict(list)
def set(self, key: str, value: str, timestamp: int) -> None:
self.ktv[key].append((timestamp, value))
@@ -109,11 +109,11 @@ class TimeMap {
public TimeMap() {
ktv = new HashMap<>();
}
-
+
public void set(String key, String value, int timestamp) {
ktv.computeIfAbsent(key, k -> new TreeMap<>()).put(timestamp, value);
}
-
+
public String get(String key, int timestamp) {
if (!ktv.containsKey(key)) {
return "";
diff --git a/solution/0900-0999/0981.Time Based Key-Value Store/README_EN.md b/solution/0900-0999/0981.Time Based Key-Value Store/README_EN.md
index e9c666304f680..31654023d6ea6 100644
--- a/solution/0900-0999/0981.Time Based Key-Value Store/README_EN.md
+++ b/solution/0900-0999/0981.Time Based Key-Value Store/README_EN.md
@@ -93,7 +93,7 @@ class TimeMap:
"""
Initialize your data structure here.
"""
- self.ktv = collections.defaultdict(list)
+ self.ktv = defaultdict(list)
def set(self, key: str, value: str, timestamp: int) -> None:
self.ktv[key].append((timestamp, value))
@@ -123,11 +123,11 @@ class TimeMap {
public TimeMap() {
ktv = new HashMap<>();
}
-
+
public void set(String key, String value, int timestamp) {
ktv.computeIfAbsent(key, k -> new TreeMap<>()).put(timestamp, value);
}
-
+
public String get(String key, int timestamp) {
if (!ktv.containsKey(key)) {
return "";
diff --git a/solution/0900-0999/0981.Time Based Key-Value Store/Solution.py b/solution/0900-0999/0981.Time Based Key-Value Store/Solution.py
index 479e1a12c3964..9d8a92219f004 100644
--- a/solution/0900-0999/0981.Time Based Key-Value Store/Solution.py
+++ b/solution/0900-0999/0981.Time Based Key-Value Store/Solution.py
@@ -4,7 +4,7 @@ def __init__(self):
"""
Initialize your data structure here.
"""
- self.ktv = collections.defaultdict(list)
+ self.ktv = defaultdict(list)
def set(self, key: str, value: str, timestamp: int) -> None:
self.ktv[key].append((timestamp, value))
@@ -15,10 +15,9 @@ def get(self, key: str, timestamp: int) -> str:
tv = self.ktv[key]
i = bisect.bisect_right(tv, (timestamp, chr(127)))
return tv[i - 1][1] if i else ''
-
# Your TimeMap object will be instantiated and called as such:
# obj = TimeMap()
# obj.set(key,value,timestamp)
-# param_2 = obj.get(key,timestamp)
\ No newline at end of file
+# param_2 = obj.get(key,timestamp)
diff --git a/solution/0900-0999/0993.Cousins in Binary Tree/README.md b/solution/0900-0999/0993.Cousins in Binary Tree/README.md
index 5c9673456e209..c3ff0bf40e61c 100644
--- a/solution/0900-0999/0993.Cousins in Binary Tree/README.md
+++ b/solution/0900-0999/0993.Cousins in Binary Tree/README.md
@@ -80,7 +80,7 @@ class Solution:
def isCousins(self, root: TreeNode, x: int, y: int) -> bool:
p = list(range(110))
d = list(range(110))
- q = collections.deque([root])
+ q = deque([root])
i = 0
while q:
n = len(q)
diff --git a/solution/0900-0999/0993.Cousins in Binary Tree/README_EN.md b/solution/0900-0999/0993.Cousins in Binary Tree/README_EN.md
index 6064a394506e1..c77b72fd3d3ec 100644
--- a/solution/0900-0999/0993.Cousins in Binary Tree/README_EN.md
+++ b/solution/0900-0999/0993.Cousins in Binary Tree/README_EN.md
@@ -72,7 +72,7 @@ class Solution:
def isCousins(self, root: TreeNode, x: int, y: int) -> bool:
p = list(range(110))
d = list(range(110))
- q = collections.deque([root])
+ q = deque([root])
i = 0
while q:
n = len(q)
diff --git a/solution/0900-0999/0993.Cousins in Binary Tree/Solution.py b/solution/0900-0999/0993.Cousins in Binary Tree/Solution.py
index f6f70c61688d0..62ad68381b760 100644
--- a/solution/0900-0999/0993.Cousins in Binary Tree/Solution.py
+++ b/solution/0900-0999/0993.Cousins in Binary Tree/Solution.py
@@ -8,7 +8,7 @@ class Solution:
def isCousins(self, root: TreeNode, x: int, y: int) -> bool:
p = list(range(110))
d = list(range(110))
- q = collections.deque([root])
+ q = deque([root])
i = 0
while q:
n = len(q)
diff --git a/solution/1100-1199/1133.Largest Unique Number/README.md b/solution/1100-1199/1133.Largest Unique Number/README.md
index 9ebe988aa761a..c04668bd07a9c 100644
--- a/solution/1100-1199/1133.Largest Unique Number/README.md
+++ b/solution/1100-1199/1133.Largest Unique Number/README.md
@@ -52,7 +52,7 @@
```python
class Solution:
def largestUniqueNumber(self, A: List[int]) -> int:
- counter = collections.Counter(A)
+ counter = Counter(A)
for i in range(1000, -1, -1):
if counter[i] == 1:
return i
diff --git a/solution/1100-1199/1133.Largest Unique Number/README_EN.md b/solution/1100-1199/1133.Largest Unique Number/README_EN.md
index d922aacc67b15..b58b1f612e502 100644
--- a/solution/1100-1199/1133.Largest Unique Number/README_EN.md
+++ b/solution/1100-1199/1133.Largest Unique Number/README_EN.md
@@ -56,7 +56,7 @@ There is no number that occurs only once.
```python
class Solution:
def largestUniqueNumber(self, A: List[int]) -> int:
- counter = collections.Counter(A)
+ counter = Counter(A)
for i in range(1000, -1, -1):
if counter[i] == 1:
return i
diff --git a/solution/1100-1199/1133.Largest Unique Number/Solution.py b/solution/1100-1199/1133.Largest Unique Number/Solution.py
index d25e8530cfd6f..617663a4b3409 100644
--- a/solution/1100-1199/1133.Largest Unique Number/Solution.py
+++ b/solution/1100-1199/1133.Largest Unique Number/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def largestUniqueNumber(self, A: List[int]) -> int:
- counter = collections.Counter(A)
+ counter = Counter(A)
for i in range(1000, -1, -1):
if counter[i] == 1:
return i
diff --git a/solution/1100-1199/1181.Before and After Puzzle/README.md b/solution/1100-1199/1181.Before and After Puzzle/README.md
index ea7228f078cd3..01fdbc17a7877 100644
--- a/solution/1100-1199/1181.Before and After Puzzle/README.md
+++ b/solution/1100-1199/1181.Before and After Puzzle/README.md
@@ -74,7 +74,7 @@
```python
class Solution:
def beforeAndAfterPuzzles(self, phrases: List[str]) -> List[str]:
- same_first_word = collections.defaultdict(set)
+ same_first_word = defaultdict(set)
for i, phrase in enumerate(phrases):
same_first_word[phrase.split()[0]].add(i)
res = set()
diff --git a/solution/1100-1199/1181.Before and After Puzzle/README_EN.md b/solution/1100-1199/1181.Before and After Puzzle/README_EN.md
index b513b4c11b964..b4f227011f9cc 100644
--- a/solution/1100-1199/1181.Before and After Puzzle/README_EN.md
+++ b/solution/1100-1199/1181.Before and After Puzzle/README_EN.md
@@ -65,7 +65,7 @@
```python
class Solution:
def beforeAndAfterPuzzles(self, phrases: List[str]) -> List[str]:
- same_first_word = collections.defaultdict(set)
+ same_first_word = defaultdict(set)
for i, phrase in enumerate(phrases):
same_first_word[phrase.split()[0]].add(i)
res = set()
diff --git a/solution/1100-1199/1181.Before and After Puzzle/Solution.py b/solution/1100-1199/1181.Before and After Puzzle/Solution.py
index 806c44b6936b8..70f07d272fe6b 100644
--- a/solution/1100-1199/1181.Before and After Puzzle/Solution.py
+++ b/solution/1100-1199/1181.Before and After Puzzle/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def beforeAndAfterPuzzles(self, phrases: List[str]) -> List[str]:
- same_first_word = collections.defaultdict(set)
+ same_first_word = defaultdict(set)
for i, phrase in enumerate(phrases):
same_first_word[phrase.split()[0]].add(i)
res = set()
diff --git a/solution/1100-1199/1182.Shortest Distance to Target Color/README.md b/solution/1100-1199/1182.Shortest Distance to Target Color/README.md
index 0077b7f717ec1..9e79664312a6d 100644
--- a/solution/1100-1199/1182.Shortest Distance to Target Color/README.md
+++ b/solution/1100-1199/1182.Shortest Distance to Target Color/README.md
@@ -63,7 +63,7 @@
```python
class Solution:
def shortestDistanceColor(self, colors: List[int], queries: List[List[int]]) -> List[int]:
- color_indexes = collections.defaultdict(list)
+ color_indexes = defaultdict(list)
for i, c in enumerate(colors):
color_indexes[c].append(i)
res = []
diff --git a/solution/1100-1199/1182.Shortest Distance to Target Color/README_EN.md b/solution/1100-1199/1182.Shortest Distance to Target Color/README_EN.md
index ab15ac39fe708..e9fc6de6c7400 100644
--- a/solution/1100-1199/1182.Shortest Distance to Target Color/README_EN.md
+++ b/solution/1100-1199/1182.Shortest Distance to Target Color/README_EN.md
@@ -40,7 +40,6 @@ The nearest 1 from index 6 is at index 3 (3 steps away).
1 <= queries[i][1] <= 3
-
## Solutions
Binary search.
@@ -52,7 +51,7 @@ Binary search.
```python
class Solution:
def shortestDistanceColor(self, colors: List[int], queries: List[List[int]]) -> List[int]:
- color_indexes = collections.defaultdict(list)
+ color_indexes = defaultdict(list)
for i, c in enumerate(colors):
color_indexes[c].append(i)
res = []
diff --git a/solution/1100-1199/1182.Shortest Distance to Target Color/Solution.py b/solution/1100-1199/1182.Shortest Distance to Target Color/Solution.py
index 1e290f01bacbe..cc3d6175f6cd3 100644
--- a/solution/1100-1199/1182.Shortest Distance to Target Color/Solution.py
+++ b/solution/1100-1199/1182.Shortest Distance to Target Color/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def shortestDistanceColor(self, colors: List[int], queries: List[List[int]]) -> List[int]:
- color_indexes = collections.defaultdict(list)
+ color_indexes = defaultdict(list)
for i, c in enumerate(colors):
color_indexes[c].append(i)
res = []
diff --git a/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README.md b/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README.md
index b7b4f51b96d5f..86670a2d11667 100644
--- a/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README.md
+++ b/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README.md
@@ -44,7 +44,7 @@
```python
class Solution:
def smallestCommonElement(self, mat: List[List[int]]) -> int:
- counter = collections.Counter()
+ counter = Counter()
for row in mat:
for num in row:
counter[num] += 1
diff --git a/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README_EN.md b/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README_EN.md
index 8c682ec827911..49d15da17e964 100644
--- a/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README_EN.md
+++ b/solution/1100-1199/1198.Find Smallest Common Element in All Rows/README_EN.md
@@ -43,7 +43,7 @@
```python
class Solution:
def smallestCommonElement(self, mat: List[List[int]]) -> int:
- counter = collections.Counter()
+ counter = Counter()
for row in mat:
for num in row:
counter[num] += 1
diff --git a/solution/1100-1199/1198.Find Smallest Common Element in All Rows/Solution.py b/solution/1100-1199/1198.Find Smallest Common Element in All Rows/Solution.py
index 9a40fa856feae..eb726829bbd61 100644
--- a/solution/1100-1199/1198.Find Smallest Common Element in All Rows/Solution.py
+++ b/solution/1100-1199/1198.Find Smallest Common Element in All Rows/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def smallestCommonElement(self, mat: List[List[int]]) -> int:
- counter = collections.Counter()
+ counter = Counter()
for row in mat:
for num in row:
counter[num] += 1
diff --git a/solution/1200-1299/1202.Smallest String With Swaps/README.md b/solution/1200-1299/1202.Smallest String With Swaps/README.md
index b59bd6e146801..491b6f2d095e1 100644
--- a/solution/1200-1299/1202.Smallest String With Swaps/README.md
+++ b/solution/1200-1299/1202.Smallest String With Swaps/README.md
@@ -140,7 +140,7 @@ class Solution:
for a, b in pairs:
p[find(a)] = find(b)
- mp = collections.defaultdict(list)
+ mp = defaultdict(list)
for i in range(n):
heapq.heappush(mp[find(i)], s[i])
chars = list(s)
diff --git a/solution/1200-1299/1202.Smallest String With Swaps/README_EN.md b/solution/1200-1299/1202.Smallest String With Swaps/README_EN.md
index d01f45232aae9..9d2596254e916 100644
--- a/solution/1200-1299/1202.Smallest String With Swaps/README_EN.md
+++ b/solution/1200-1299/1202.Smallest String With Swaps/README_EN.md
@@ -52,7 +52,6 @@ Swap s[0] and s[1], s = "abc"
s
only contains lower case English letters.
-
## Solutions
@@ -73,7 +72,7 @@ class Solution:
for a, b in pairs:
p[find(a)] = find(b)
- mp = collections.defaultdict(list)
+ mp = defaultdict(list)
for i in range(n):
heapq.heappush(mp[find(i)], s[i])
chars = list(s)
diff --git a/solution/1200-1299/1202.Smallest String With Swaps/Solution.py b/solution/1200-1299/1202.Smallest String With Swaps/Solution.py
index 851b1d341e404..22b7deaf5fc33 100644
--- a/solution/1200-1299/1202.Smallest String With Swaps/Solution.py
+++ b/solution/1200-1299/1202.Smallest String With Swaps/Solution.py
@@ -11,7 +11,7 @@ def find(x):
for a, b in pairs:
p[find(a)] = find(b)
- mp = collections.defaultdict(list)
+ mp = defaultdict(list)
for i in range(n):
heapq.heappush(mp[find(i)], s[i])
chars = list(s)
diff --git a/solution/1200-1299/1207.Unique Number of Occurrences/README.md b/solution/1200-1299/1207.Unique Number of Occurrences/README.md
index 8805be0488dd9..0e6869712395e 100644
--- a/solution/1200-1299/1207.Unique Number of Occurrences/README.md
+++ b/solution/1200-1299/1207.Unique Number of Occurrences/README.md
@@ -54,7 +54,7 @@
```python
class Solution:
def uniqueOccurrences(self, arr: List[int]) -> bool:
- counter = collections.Counter(arr)
+ counter = Counter(arr)
s = set()
for num in counter.values():
if num in s:
diff --git a/solution/1200-1299/1207.Unique Number of Occurrences/README_EN.md b/solution/1200-1299/1207.Unique Number of Occurrences/README_EN.md
index e197ef4872670..9ddbb07e8a0f8 100644
--- a/solution/1200-1299/1207.Unique Number of Occurrences/README_EN.md
+++ b/solution/1200-1299/1207.Unique Number of Occurrences/README_EN.md
@@ -45,7 +45,7 @@
```python
class Solution:
def uniqueOccurrences(self, arr: List[int]) -> bool:
- counter = collections.Counter(arr)
+ counter = Counter(arr)
s = set()
for num in counter.values():
if num in s:
diff --git a/solution/1200-1299/1207.Unique Number of Occurrences/Solution.py b/solution/1200-1299/1207.Unique Number of Occurrences/Solution.py
index 87303d7735520..fc0aa2ce9621d 100644
--- a/solution/1200-1299/1207.Unique Number of Occurrences/Solution.py
+++ b/solution/1200-1299/1207.Unique Number of Occurrences/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def uniqueOccurrences(self, arr: List[int]) -> bool:
- counter = collections.Counter(arr)
+ counter = Counter(arr)
s = set()
for num in counter.values():
if num in s:
diff --git a/solution/1200-1299/1258.Synonymous Sentences/README.md b/solution/1200-1299/1258.Synonymous Sentences/README.md
index efdd64c525701..73b2c45c45fc3 100644
--- a/solution/1200-1299/1258.Synonymous Sentences/README.md
+++ b/solution/1200-1299/1258.Synonymous Sentences/README.md
@@ -71,7 +71,7 @@ class Solution:
for a, b in synonyms:
p[find(a)] = find(b)
- s = collections.defaultdict(set)
+ s = defaultdict(set)
for a, b in synonyms:
s[find(a)].add(a)
s[find(b)].add(b)
diff --git a/solution/1200-1299/1258.Synonymous Sentences/README_EN.md b/solution/1200-1299/1258.Synonymous Sentences/README_EN.md
index 7bc0314abfe19..2717aece379c5 100644
--- a/solution/1200-1299/1258.Synonymous Sentences/README_EN.md
+++ b/solution/1200-1299/1258.Synonymous Sentences/README_EN.md
@@ -76,7 +76,7 @@ class Solution:
for a, b in synonyms:
p[find(a)] = find(b)
- s = collections.defaultdict(set)
+ s = defaultdict(set)
for a, b in synonyms:
s[find(a)].add(a)
s[find(b)].add(b)
diff --git a/solution/1200-1299/1258.Synonymous Sentences/Solution.py b/solution/1200-1299/1258.Synonymous Sentences/Solution.py
index e9e550452124d..d00231b17a381 100644
--- a/solution/1200-1299/1258.Synonymous Sentences/Solution.py
+++ b/solution/1200-1299/1258.Synonymous Sentences/Solution.py
@@ -13,7 +13,7 @@ def find(x):
for a, b in synonyms:
p[find(a)] = find(b)
- s = collections.defaultdict(set)
+ s = defaultdict(set)
for a, b in synonyms:
s[find(a)].add(a)
s[find(b)].add(b)
diff --git a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README.md b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README.md
index af6ab0a8897c6..c2637517d2662 100644
--- a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README.md
+++ b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README.md
@@ -49,7 +49,7 @@
```python
class Solution:
def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]:
- mp = collections.defaultdict(list)
+ mp = defaultdict(list)
for i, x in enumerate(groupSizes):
mp[x].append(i)
res = []
diff --git a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README_EN.md b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README_EN.md
index 3e1f965865db0..d35cface9a643 100644
--- a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README_EN.md
+++ b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README_EN.md
@@ -50,7 +50,7 @@ Other possible solutions are [[2,1,6],[5],[0,4,3]] and [[5],[0,6,2],[4,3,1]].
```python
class Solution:
def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]:
- mp = collections.defaultdict(list)
+ mp = defaultdict(list)
for i, x in enumerate(groupSizes):
mp[x].append(i)
res = []
diff --git a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/Solution.py b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/Solution.py
index 7fba269914e41..409ecedda7de9 100644
--- a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/Solution.py
+++ b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]:
- mp = collections.defaultdict(list)
+ mp = defaultdict(list)
for i, x in enumerate(groupSizes):
mp[x].append(i)
res = []
diff --git a/solution/1300-1399/1302.Deepest Leaves Sum/README.md b/solution/1300-1399/1302.Deepest Leaves Sum/README.md
index aa0fa93208853..b3acfd8c1cea9 100644
--- a/solution/1300-1399/1302.Deepest Leaves Sum/README.md
+++ b/solution/1300-1399/1302.Deepest Leaves Sum/README.md
@@ -35,7 +35,6 @@
1 <= Node.val <= 100
-
## 解法
@@ -57,7 +56,7 @@
# self.right = right
class Solution:
def deepestLeavesSum(self, root: TreeNode) -> int:
- q = collections.deque([root])
+ q = deque([root])
s = 0
while q:
n = len(q)
diff --git a/solution/1300-1399/1302.Deepest Leaves Sum/README_EN.md b/solution/1300-1399/1302.Deepest Leaves Sum/README_EN.md
index 086394ff26b57..b2c5d4fbccea8 100644
--- a/solution/1300-1399/1302.Deepest Leaves Sum/README_EN.md
+++ b/solution/1300-1399/1302.Deepest Leaves Sum/README_EN.md
@@ -46,7 +46,7 @@ BFS.
# self.right = right
class Solution:
def deepestLeavesSum(self, root: TreeNode) -> int:
- q = collections.deque([root])
+ q = deque([root])
s = 0
while q:
n = len(q)
diff --git a/solution/1300-1399/1302.Deepest Leaves Sum/Solution.py b/solution/1300-1399/1302.Deepest Leaves Sum/Solution.py
index 7e3a2aa81cdfa..57d05969bece9 100644
--- a/solution/1300-1399/1302.Deepest Leaves Sum/Solution.py
+++ b/solution/1300-1399/1302.Deepest Leaves Sum/Solution.py
@@ -6,7 +6,7 @@
# self.right = right
class Solution:
def deepestLeavesSum(self, root: TreeNode) -> int:
- q = collections.deque([root])
+ q = deque([root])
s = 0
while q:
n = len(q)
diff --git a/solution/1300-1399/1346.Check If N and Its Double Exist/README.md b/solution/1300-1399/1346.Check If N and Its Double Exist/README.md
index 98c19e1350b9c..80004125d1258 100644
--- a/solution/1300-1399/1346.Check If N and Its Double Exist/README.md
+++ b/solution/1300-1399/1346.Check If N and Its Double Exist/README.md
@@ -48,7 +48,6 @@
-10^3 <= arr[i] <= 10^3
-
## 解法
@@ -62,7 +61,7 @@
```python
class Solution:
def checkIfExist(self, arr: List[int]) -> bool:
- map = collections.defaultdict(int)
+ map = defaultdict(int)
for i, num in enumerate(arr):
map[num] = i
for i, num in enumerate(arr):
@@ -95,19 +94,19 @@ class Solution {
```ts
function checkIfExist(arr: number[]): boolean {
- for (let i = arr.length - 1; i >= 0; --i) {
- let cur = arr[i];
- let t1 = 2 * cur;
- if (arr.includes(t1) && arr.indexOf(t1) != i) {
- return true;
- }
- let t2 = cur >> 1;
- if (cur % 2 == 0 && arr.includes(t2) && arr.indexOf(t2) != i) {
- return true;
- }
+ for (let i = arr.length - 1; i >= 0; --i) {
+ let cur = arr[i];
+ let t1 = 2 * cur;
+ if (arr.includes(t1) && arr.indexOf(t1) != i) {
+ return true;
}
- return false;
-};
+ let t2 = cur >> 1;
+ if (cur % 2 == 0 && arr.includes(t2) && arr.indexOf(t2) != i) {
+ return true;
+ }
+ }
+ return false;
+}
```
### **C++**
diff --git a/solution/1300-1399/1346.Check If N and Its Double Exist/README_EN.md b/solution/1300-1399/1346.Check If N and Its Double Exist/README_EN.md
index f74173a360526..c03cd6f14c046 100644
--- a/solution/1300-1399/1346.Check If N and Its Double Exist/README_EN.md
+++ b/solution/1300-1399/1346.Check If N and Its Double Exist/README_EN.md
@@ -47,7 +47,6 @@
-10^3 <= arr[i] <= 10^3
-
## Solutions
@@ -57,7 +56,7 @@
```python
class Solution:
def checkIfExist(self, arr: List[int]) -> bool:
- map = collections.defaultdict(int)
+ map = defaultdict(int)
for i, num in enumerate(arr):
map[num] = i
for i, num in enumerate(arr):
@@ -88,19 +87,19 @@ class Solution {
```ts
function checkIfExist(arr: number[]): boolean {
- for (let i = arr.length - 1; i >= 0; --i) {
- let cur = arr[i];
- let t1 = 2 * cur;
- if (arr.includes(t1) && arr.indexOf(t1) != i) {
- return true;
- }
- let t2 = cur >> 1;
- if (cur % 2 == 0 && arr.includes(t2) && arr.indexOf(t2) != i) {
- return true;
- }
+ for (let i = arr.length - 1; i >= 0; --i) {
+ let cur = arr[i];
+ let t1 = 2 * cur;
+ if (arr.includes(t1) && arr.indexOf(t1) != i) {
+ return true;
}
- return false;
-};
+ let t2 = cur >> 1;
+ if (cur % 2 == 0 && arr.includes(t2) && arr.indexOf(t2) != i) {
+ return true;
+ }
+ }
+ return false;
+}
```
### **C++**
diff --git a/solution/1300-1399/1346.Check If N and Its Double Exist/Solution.py b/solution/1300-1399/1346.Check If N and Its Double Exist/Solution.py
index e720d289c1913..6db5f3f67824a 100644
--- a/solution/1300-1399/1346.Check If N and Its Double Exist/Solution.py
+++ b/solution/1300-1399/1346.Check If N and Its Double Exist/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def checkIfExist(self, arr: List[int]) -> bool:
- map = collections.defaultdict(int)
+ map = defaultdict(int)
for i, num in enumerate(arr):
map[num] = i
for i, num in enumerate(arr):
diff --git a/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README.md b/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README.md
index f635050f34047..4d13173db5f72 100644
--- a/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README.md
+++ b/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README.md
@@ -72,7 +72,7 @@
```python
class Solution:
def minSteps(self, s: str, t: str) -> int:
- counter = collections.Counter(s)
+ counter = Counter(s)
res = 0
for c in t:
if counter[c] > 0:
diff --git a/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README_EN.md b/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README_EN.md
index 3d4fc8fbd8e50..69c1b0b93f9cc 100644
--- a/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README_EN.md
+++ b/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README_EN.md
@@ -67,7 +67,7 @@
```python
class Solution:
def minSteps(self, s: str, t: str) -> int:
- counter = collections.Counter(s)
+ counter = Counter(s)
res = 0
for c in t:
if counter[c] > 0:
diff --git a/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/Solution.py b/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/Solution.py
index afaab280ca051..d310519da2e85 100644
--- a/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/Solution.py
+++ b/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def minSteps(self, s: str, t: str) -> int:
- counter = collections.Counter(s)
+ counter = Counter(s)
res = 0
for c in t:
if counter[c] > 0:
diff --git a/solution/1300-1399/1394.Find Lucky Integer in an Array/README.md b/solution/1300-1399/1394.Find Lucky Integer in an Array/README.md
index 9dfffd75ff92b..9b94f104bf8ba 100644
--- a/solution/1300-1399/1394.Find Lucky Integer in an Array/README.md
+++ b/solution/1300-1399/1394.Find Lucky Integer in an Array/README.md
@@ -72,7 +72,7 @@
```python
class Solution:
def findLucky(self, arr: List[int]) -> int:
- counter = collections.Counter(arr)
+ counter = Counter(arr)
ans = -1
for num, n in counter.items():
if num == n and ans < num:
diff --git a/solution/1300-1399/1394.Find Lucky Integer in an Array/README_EN.md b/solution/1300-1399/1394.Find Lucky Integer in an Array/README_EN.md
index eacf299ed0fbc..fe32d8c8c8f10 100644
--- a/solution/1300-1399/1394.Find Lucky Integer in an Array/README_EN.md
+++ b/solution/1300-1399/1394.Find Lucky Integer in an Array/README_EN.md
@@ -84,7 +84,7 @@
```python
class Solution:
def findLucky(self, arr: List[int]) -> int:
- counter = collections.Counter(arr)
+ counter = Counter(arr)
ans = -1
for num, n in counter.items():
if num == n and ans < num:
diff --git a/solution/1300-1399/1394.Find Lucky Integer in an Array/Solution.py b/solution/1300-1399/1394.Find Lucky Integer in an Array/Solution.py
index b538d367a5e29..0bfae7ae86fbf 100644
--- a/solution/1300-1399/1394.Find Lucky Integer in an Array/Solution.py
+++ b/solution/1300-1399/1394.Find Lucky Integer in an Array/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def findLucky(self, arr: List[int]) -> int:
- counter = collections.Counter(arr)
+ counter = Counter(arr)
ans = -1
for num, n in counter.items():
if num == n and ans < num:
diff --git a/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README.md b/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README.md
index c6153c6e01cb1..95fe64ccc8ae8 100644
--- a/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README.md
+++ b/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README.md
@@ -71,7 +71,7 @@ class Solution:
def displayTable(self, orders: List[List[str]]) -> List[List[str]]:
tables = set()
foods = set()
- mp = collections.Counter()
+ mp = Counter()
for _, table, food in orders:
tables.add(int(table))
foods.add(food)
diff --git a/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README_EN.md b/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README_EN.md
index 3431d99c6b37e..0d027eeafa8bb 100644
--- a/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README_EN.md
+++ b/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/README_EN.md
@@ -87,7 +87,7 @@ class Solution:
def displayTable(self, orders: List[List[str]]) -> List[List[str]]:
tables = set()
foods = set()
- mp = collections.Counter()
+ mp = Counter()
for _, table, food in orders:
tables.add(int(table))
foods.add(food)
diff --git a/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/Solution.py b/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/Solution.py
index e80fbe845f834..e602f22e225cc 100644
--- a/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/Solution.py
+++ b/solution/1400-1499/1418.Display Table of Food Orders in a Restaurant/Solution.py
@@ -2,7 +2,7 @@ class Solution:
def displayTable(self, orders: List[List[str]]) -> List[List[str]]:
tables = set()
foods = set()
- mp = collections.Counter()
+ mp = Counter()
for _, table, food in orders:
tables.add(int(table))
foods.add(food)
diff --git a/solution/1400-1499/1429.First Unique Number/README.md b/solution/1400-1499/1429.First Unique Number/README.md
index 55c4109a7bf88..7afc30afa3931 100644
--- a/solution/1400-1499/1429.First Unique Number/README.md
+++ b/solution/1400-1499/1429.First Unique Number/README.md
@@ -98,8 +98,8 @@ firstUnique.showFirstUnique(); // 返回 -1
class FirstUnique:
def __init__(self, nums: List[int]):
- self.counter = collections.OrderedDict()
- self.unique_nums = collections.OrderedDict()
+ self.counter = OrderedDict()
+ self.unique_nums = OrderedDict()
for num in nums:
self.counter[num] = self.counter.get(num, 0) + 1
for k, v in self.counter.items():
diff --git a/solution/1400-1499/1429.First Unique Number/README_EN.md b/solution/1400-1499/1429.First Unique Number/README_EN.md
index 2651e11107897..888396d942c79 100644
--- a/solution/1400-1499/1429.First Unique Number/README_EN.md
+++ b/solution/1400-1499/1429.First Unique Number/README_EN.md
@@ -88,8 +88,8 @@ firstUnique.showFirstUnique(); // return -1
class FirstUnique:
def __init__(self, nums: List[int]):
- self.counter = collections.OrderedDict()
- self.unique_nums = collections.OrderedDict()
+ self.counter = OrderedDict()
+ self.unique_nums = OrderedDict()
for num in nums:
self.counter[num] = self.counter.get(num, 0) + 1
for k, v in self.counter.items():
diff --git a/solution/1400-1499/1429.First Unique Number/Solution.py b/solution/1400-1499/1429.First Unique Number/Solution.py
index 7047a063d6e54..25bad8f2175b4 100644
--- a/solution/1400-1499/1429.First Unique Number/Solution.py
+++ b/solution/1400-1499/1429.First Unique Number/Solution.py
@@ -1,8 +1,8 @@
class FirstUnique:
def __init__(self, nums: List[int]):
- self.counter = collections.OrderedDict()
- self.unique_nums = collections.OrderedDict()
+ self.counter = OrderedDict()
+ self.unique_nums = OrderedDict()
for num in nums:
self.counter[num] = self.counter.get(num, 0) + 1
for k, v in self.counter.items():
@@ -27,4 +27,4 @@ def add(self, value: int) -> None:
# Your FirstUnique object will be instantiated and called as such:
# obj = FirstUnique(nums)
# param_1 = obj.showFirstUnique()
-# obj.add(value)
\ No newline at end of file
+# obj.add(value)
diff --git a/solution/1500-1599/1500.Design a File Sharing System/README.md b/solution/1500-1599/1500.Design a File Sharing System/README.md
index 8e9e724e60ca0..6faf2f91c0484 100644
--- a/solution/1500-1599/1500.Design a File Sharing System/README.md
+++ b/solution/1500-1599/1500.Design a File Sharing System/README.md
@@ -96,7 +96,7 @@ class FileSharing:
self.cur = 0
self.chunks = m
self.reused = []
- self.user_chunks = collections.defaultdict(set)
+ self.user_chunks = defaultdict(set)
def join(self, ownedChunks: List[int]) -> int:
if self.reused:
@@ -146,7 +146,7 @@ class FileSharing {
reused = new TreeSet<>();
userChunks = new TreeMap<>();
}
-
+
public int join(List ownedChunks) {
int userID;
if (reused.isEmpty()) {
@@ -158,12 +158,12 @@ class FileSharing {
userChunks.put(userID, new HashSet<>(ownedChunks));
return userID;
}
-
+
public void leave(int userID) {
reused.add(userID);
userChunks.remove(userID);
}
-
+
public List request(int userID, int chunkID) {
if (chunkID < 1 || chunkID > chunks) {
return Collections.emptyList();
diff --git a/solution/1500-1599/1500.Design a File Sharing System/README_EN.md b/solution/1500-1599/1500.Design a File Sharing System/README_EN.md
index 32083e3a7a19f..fad08858e21a8 100644
--- a/solution/1500-1599/1500.Design a File Sharing System/README_EN.md
+++ b/solution/1500-1599/1500.Design a File Sharing System/README_EN.md
@@ -118,7 +118,7 @@ class FileSharing:
self.cur = 0
self.chunks = m
self.reused = []
- self.user_chunks = collections.defaultdict(set)
+ self.user_chunks = defaultdict(set)
def join(self, ownedChunks: List[int]) -> int:
if self.reused:
@@ -166,7 +166,7 @@ class FileSharing {
reused = new TreeSet<>();
userChunks = new TreeMap<>();
}
-
+
public int join(List ownedChunks) {
int userID;
if (reused.isEmpty()) {
@@ -178,12 +178,12 @@ class FileSharing {
userChunks.put(userID, new HashSet<>(ownedChunks));
return userID;
}
-
+
public void leave(int userID) {
reused.add(userID);
userChunks.remove(userID);
}
-
+
public List request(int userID, int chunkID) {
if (chunkID < 1 || chunkID > chunks) {
return Collections.emptyList();
diff --git a/solution/1500-1599/1500.Design a File Sharing System/Solution.py b/solution/1500-1599/1500.Design a File Sharing System/Solution.py
index cacca5753b2c6..310263df81300 100644
--- a/solution/1500-1599/1500.Design a File Sharing System/Solution.py
+++ b/solution/1500-1599/1500.Design a File Sharing System/Solution.py
@@ -4,7 +4,7 @@ def __init__(self, m: int):
self.cur = 0
self.chunks = m
self.reused = []
- self.user_chunks = collections.defaultdict(set)
+ self.user_chunks = defaultdict(set)
def join(self, ownedChunks: List[int]) -> int:
if self.reused:
diff --git a/solution/1500-1599/1512.Number of Good Pairs/README.md b/solution/1500-1599/1512.Number of Good Pairs/README.md
index 8b720c2b6049b..039ad2e3045a9 100644
--- a/solution/1500-1599/1512.Number of Good Pairs/README.md
+++ b/solution/1500-1599/1512.Number of Good Pairs/README.md
@@ -55,7 +55,7 @@
```python
class Solution:
def numIdenticalPairs(self, nums: List[int]) -> int:
- counter = collections.Counter(nums)
+ counter = Counter(nums)
return sum([x * (x - 1) for x in counter.values()]) >> 1
```
diff --git a/solution/1500-1599/1512.Number of Good Pairs/README_EN.md b/solution/1500-1599/1512.Number of Good Pairs/README_EN.md
index 39d8df0d0a100..8a5b2d2afa380 100644
--- a/solution/1500-1599/1512.Number of Good Pairs/README_EN.md
+++ b/solution/1500-1599/1512.Number of Good Pairs/README_EN.md
@@ -64,7 +64,7 @@
```python
class Solution:
def numIdenticalPairs(self, nums: List[int]) -> int:
- counter = collections.Counter(nums)
+ counter = Counter(nums)
return sum([x * (x - 1) for x in counter.values()]) >> 1
```
diff --git a/solution/1500-1599/1512.Number of Good Pairs/Solution.py b/solution/1500-1599/1512.Number of Good Pairs/Solution.py
index 8d9454ab28538..379772cbfd12e 100644
--- a/solution/1500-1599/1512.Number of Good Pairs/Solution.py
+++ b/solution/1500-1599/1512.Number of Good Pairs/Solution.py
@@ -1,4 +1,4 @@
class Solution:
def numIdenticalPairs(self, nums: List[int]) -> int:
- counter = collections.Counter(nums)
+ counter = Counter(nums)
return sum([x * (x - 1) for x in counter.values()]) >> 1
diff --git a/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README.md b/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README.md
index 121ec5a0239d9..51673cc0fae37 100644
--- a/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README.md
+++ b/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README.md
@@ -70,7 +70,7 @@ BFS 层序遍历。
# self.right = right
class Solution:
def findNearestRightNode(self, root: TreeNode, u: TreeNode) -> TreeNode:
- q = collections.deque([root])
+ q = deque([root])
while q:
n = len(q)
for i in range(n):
diff --git a/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README_EN.md b/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README_EN.md
index 67df3558c91cd..891188c2abe2d 100644
--- a/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README_EN.md
+++ b/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/README_EN.md
@@ -68,7 +68,7 @@ BFS.
# self.right = right
class Solution:
def findNearestRightNode(self, root: TreeNode, u: TreeNode) -> TreeNode:
- q = collections.deque([root])
+ q = deque([root])
while q:
n = len(q)
for i in range(n):
diff --git a/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/Solution.py b/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/Solution.py
index 8c700546e8945..ca96fd294880a 100644
--- a/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/Solution.py
+++ b/solution/1600-1699/1602.Find Nearest Right Node in Binary Tree/Solution.py
@@ -6,7 +6,7 @@
# self.right = right
class Solution:
def findNearestRightNode(self, root: TreeNode, u: TreeNode) -> TreeNode:
- q = collections.deque([root])
+ q = deque([root])
while q:
n = len(q)
for i in range(n):
diff --git a/solution/1600-1699/1609.Even Odd Tree/README.md b/solution/1600-1699/1609.Even Odd Tree/README.md
index 2c30f2b4e9645..2728743b0f642 100644
--- a/solution/1600-1699/1609.Even Odd Tree/README.md
+++ b/solution/1600-1699/1609.Even Odd Tree/README.md
@@ -102,7 +102,7 @@ BFS。
class Solution:
def isEvenOddTree(self, root: TreeNode) -> bool:
even = True
- q = collections.deque([root])
+ q = deque([root])
while q:
n = len(q)
prev = 0 if even else 10 ** 6
diff --git a/solution/1600-1699/1609.Even Odd Tree/README_EN.md b/solution/1600-1699/1609.Even Odd Tree/README_EN.md
index 840537911e550..332d3d71ff484 100644
--- a/solution/1600-1699/1609.Even Odd Tree/README_EN.md
+++ b/solution/1600-1699/1609.Even Odd Tree/README_EN.md
@@ -94,7 +94,7 @@ BFS.
class Solution:
def isEvenOddTree(self, root: TreeNode) -> bool:
even = True
- q = collections.deque([root])
+ q = deque([root])
while q:
n = len(q)
prev = 0 if even else 10 ** 6
diff --git a/solution/1600-1699/1609.Even Odd Tree/Solution.py b/solution/1600-1699/1609.Even Odd Tree/Solution.py
index 35c717bea96ae..1ce8c3e686422 100644
--- a/solution/1600-1699/1609.Even Odd Tree/Solution.py
+++ b/solution/1600-1699/1609.Even Odd Tree/Solution.py
@@ -7,7 +7,7 @@
class Solution:
def isEvenOddTree(self, root: TreeNode) -> bool:
even = True
- q = collections.deque([root])
+ q = deque([root])
while q:
n = len(q)
prev = 0 if even else 10 ** 6
diff --git a/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README.md b/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README.md
index 51a40eecd16ba..f047585a6b1d8 100644
--- a/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README.md
+++ b/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README.md
@@ -48,7 +48,6 @@
s
仅含小写英文字母
-
## 解法
@@ -64,7 +63,7 @@
```python
class Solution:
def minDeletions(self, s: str) -> int:
- counter = collections.Counter(s)
+ counter = Counter(s)
vals = [v for v in counter.values()]
vals.sort(reverse=True)
ans = 0
@@ -103,21 +102,21 @@ class Solution {
```ts
function minDeletions(s: string): number {
- let map = {};
- for (let c of s) {
- map[c] = (map[c] || 0) + 1;
- }
- let ans = 0;
- let vals: number[] = Object.values(map);
- vals.sort((a, b) => a - b);
- for (let i = 1; i < vals.length; ++i) {
- while(vals[i] > 0 && i != vals.indexOf(vals[i])) {
- --vals[i];
- ++ans;
- }
+ let map = {};
+ for (let c of s) {
+ map[c] = (map[c] || 0) + 1;
+ }
+ let ans = 0;
+ let vals: number[] = Object.values(map);
+ vals.sort((a, b) => a - b);
+ for (let i = 1; i < vals.length; ++i) {
+ while (vals[i] > 0 && i != vals.indexOf(vals[i])) {
+ --vals[i];
+ ++ans;
}
- return ans;
-};
+ }
+ return ans;
+}
```
### **...**
diff --git a/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README_EN.md b/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README_EN.md
index 2b846243e0b87..025d1d6898891 100644
--- a/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README_EN.md
+++ b/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/README_EN.md
@@ -44,7 +44,6 @@ Note that we only care about characters that are still in the string at the end
s
contains only lowercase English letters.
-
## Solutions
@@ -54,7 +53,7 @@ Note that we only care about characters that are still in the string at the end
```python
class Solution:
def minDeletions(self, s: str) -> int:
- counter = collections.Counter(s)
+ counter = Counter(s)
vals = [v for v in counter.values()]
vals.sort(reverse=True)
ans = 0
@@ -91,21 +90,21 @@ class Solution {
```ts
function minDeletions(s: string): number {
- let map = {};
- for (let c of s) {
- map[c] = (map[c] || 0) + 1;
- }
- let ans = 0;
- let vals: number[] = Object.values(map);
- vals.sort((a, b) => a - b);
- for (let i = 1; i < vals.length; ++i) {
- while(vals[i] > 0 && i != vals.indexOf(vals[i])) {
- --vals[i];
- ++ans;
- }
+ let map = {};
+ for (let c of s) {
+ map[c] = (map[c] || 0) + 1;
+ }
+ let ans = 0;
+ let vals: number[] = Object.values(map);
+ vals.sort((a, b) => a - b);
+ for (let i = 1; i < vals.length; ++i) {
+ while (vals[i] > 0 && i != vals.indexOf(vals[i])) {
+ --vals[i];
+ ++ans;
}
- return ans;
-};
+ }
+ return ans;
+}
```
### **...**
diff --git a/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/Solution.py b/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/Solution.py
index c712c0c6b2b7c..acad0ebf257e1 100644
--- a/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/Solution.py
+++ b/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def minDeletions(self, s: str) -> int:
- counter = collections.Counter(s)
+ counter = Counter(s)
vals = [v for v in counter.values()]
vals.sort(reverse=True)
ans = 0
diff --git a/solution/1600-1699/1660.Correct a Binary Tree/README.md b/solution/1600-1699/1660.Correct a Binary Tree/README.md
index bfea7d2c7d04d..2d818b803f6f7 100644
--- a/solution/1600-1699/1660.Correct a Binary Tree/README.md
+++ b/solution/1600-1699/1660.Correct a Binary Tree/README.md
@@ -79,7 +79,7 @@
# self.right = right
class Solution:
def correctBinaryTree(self, root: TreeNode) -> TreeNode:
- q = collections.deque([root])
+ q = deque([root])
res = root
p = {}
while q:
@@ -115,7 +115,7 @@ class Solution:
# self.right = right
class Solution:
def correctBinaryTree(self, root: TreeNode) -> TreeNode:
- q = collections.deque([root])
+ q = deque([root])
while q:
n = len(q)
for _ in range(n):
diff --git a/solution/1600-1699/1660.Correct a Binary Tree/README_EN.md b/solution/1600-1699/1660.Correct a Binary Tree/README_EN.md
index 4ca6fce358a83..ffd681e2808ab 100644
--- a/solution/1600-1699/1660.Correct a Binary Tree/README_EN.md
+++ b/solution/1600-1699/1660.Correct a Binary Tree/README_EN.md
@@ -79,7 +79,7 @@
# self.right = right
class Solution:
def correctBinaryTree(self, root: TreeNode) -> TreeNode:
- q = collections.deque([root])
+ q = deque([root])
res = root
p = {}
while q:
@@ -113,7 +113,7 @@ class Solution:
# self.right = right
class Solution:
def correctBinaryTree(self, root: TreeNode) -> TreeNode:
- q = collections.deque([root])
+ q = deque([root])
while q:
n = len(q)
for _ in range(n):
diff --git a/solution/1600-1699/1670.Design Front Middle Back Queue/README.md b/solution/1600-1699/1670.Design Front Middle Back Queue/README.md
index 45713304914ff..caa21ce0e1d83 100644
--- a/solution/1600-1699/1670.Design Front Middle Back Queue/README.md
+++ b/solution/1600-1699/1670.Design Front Middle Back Queue/README.md
@@ -76,8 +76,8 @@ q.popFront(); // 返回 -1 -> [] (队列为空)
class FrontMiddleBackQueue:
def __init__(self):
- self.left = collections.deque()
- self.right = collections.deque()
+ self.left = deque()
+ self.right = deque()
def pushFront(self, val: int) -> None:
self.left.appendleft(val)
@@ -223,80 +223,83 @@ class FrontMiddleBackQueue {
### **JavaScript**
```js
-var FrontMiddleBackQueue = function() {
- this.left = [];
- this.right = [];
+var FrontMiddleBackQueue = function () {
+ this.left = [];
+ this.right = [];
};
-/**
+/**
* @param {number} val
* @return {void}
*/
-FrontMiddleBackQueue.prototype.pushFront = function(val) {
- this.left.unshift(val);
- this.rebalance();
+FrontMiddleBackQueue.prototype.pushFront = function (val) {
+ this.left.unshift(val);
+ this.rebalance();
};
-/**
+/**
* @param {number} val
* @return {void}
*/
-FrontMiddleBackQueue.prototype.pushMiddle = function(val) {
- this.left.push(val);
- this.rebalance();
+FrontMiddleBackQueue.prototype.pushMiddle = function (val) {
+ this.left.push(val);
+ this.rebalance();
};
-/**
+/**
* @param {number} val
* @return {void}
*/
-FrontMiddleBackQueue.prototype.pushBack = function(val) {
- this.right.push(val);
- this.rebalance();
+FrontMiddleBackQueue.prototype.pushBack = function (val) {
+ this.right.push(val);
+ this.rebalance();
};
/**
* @return {number}
*/
-FrontMiddleBackQueue.prototype.popFront = function() {
- if (this.isEmpty()) return -1;
- let num = this.left.length == 0 ? this.right.shift() : this.left.shift();
- this.rebalance();
- return num;
+FrontMiddleBackQueue.prototype.popFront = function () {
+ if (this.isEmpty()) return -1;
+ let num = this.left.length == 0 ? this.right.shift() : this.left.shift();
+ this.rebalance();
+ return num;
};
/**
* @return {number}
*/
-FrontMiddleBackQueue.prototype.popMiddle = function() {
- if (this.isEmpty()) return -1;
- let num = this.left.length == this.right.length ? this.left.pop() : this.right.shift();
- this.rebalance();
- return num;
+FrontMiddleBackQueue.prototype.popMiddle = function () {
+ if (this.isEmpty()) return -1;
+ let num =
+ this.left.length == this.right.length
+ ? this.left.pop()
+ : this.right.shift();
+ this.rebalance();
+ return num;
};
/**
* @return {number}
*/
-FrontMiddleBackQueue.prototype.popBack = function() {
- if (this.isEmpty()) return -1;
- let num = this.right.pop();
- this.rebalance();
- return num;
+FrontMiddleBackQueue.prototype.popBack = function () {
+ if (this.isEmpty()) return -1;
+ let num = this.right.pop();
+ this.rebalance();
+ return num;
};
FrontMiddleBackQueue.prototype.rebalance = function () {
- while (this.left.length > this.right.length) {
- this.right.unshift(this.left.pop());
- }
- while (this.right.length > this.left.length + 1) {
- this.left.push(this.right.shift());
- }
-}
+ while (this.left.length > this.right.length) {
+ this.right.unshift(this.left.pop());
+ }
+ while (this.right.length > this.left.length + 1) {
+ this.left.push(this.right.shift());
+ }
+};
FrontMiddleBackQueue.prototype.isEmpty = function () {
- return this.left.length == 0 && this.right.length == 0;
-}
+ return this.left.length == 0 && this.right.length == 0;
+};
/**
* Your FrontMiddleBackQueue object will be instantiated and called as such:
diff --git a/solution/1600-1699/1670.Design Front Middle Back Queue/README_EN.md b/solution/1600-1699/1670.Design Front Middle Back Queue/README_EN.md
index bea6e284413b9..cd7f8eb5a257a 100644
--- a/solution/1600-1699/1670.Design Front Middle Back Queue/README_EN.md
+++ b/solution/1600-1699/1670.Design Front Middle Back Queue/README_EN.md
@@ -66,8 +66,8 @@ q.popFront(); // return -1 -> [] (The queue is empty)
class FrontMiddleBackQueue:
def __init__(self):
- self.left = collections.deque()
- self.right = collections.deque()
+ self.left = deque()
+ self.right = deque()
def pushFront(self, val: int) -> None:
self.left.appendleft(val)
@@ -211,80 +211,83 @@ class FrontMiddleBackQueue {
### **JavaScript**
```js
-var FrontMiddleBackQueue = function() {
- this.left = [];
- this.right = [];
+var FrontMiddleBackQueue = function () {
+ this.left = [];
+ this.right = [];
};
-/**
+/**
* @param {number} val
* @return {void}
*/
-FrontMiddleBackQueue.prototype.pushFront = function(val) {
- this.left.unshift(val);
- this.rebalance();
+FrontMiddleBackQueue.prototype.pushFront = function (val) {
+ this.left.unshift(val);
+ this.rebalance();
};
-/**
+/**
* @param {number} val
* @return {void}
*/
-FrontMiddleBackQueue.prototype.pushMiddle = function(val) {
- this.left.push(val);
- this.rebalance();
+FrontMiddleBackQueue.prototype.pushMiddle = function (val) {
+ this.left.push(val);
+ this.rebalance();
};
-/**
+/**
* @param {number} val
* @return {void}
*/
-FrontMiddleBackQueue.prototype.pushBack = function(val) {
- this.right.push(val);
- this.rebalance();
+FrontMiddleBackQueue.prototype.pushBack = function (val) {
+ this.right.push(val);
+ this.rebalance();
};
/**
* @return {number}
*/
-FrontMiddleBackQueue.prototype.popFront = function() {
- if (this.isEmpty()) return -1;
- let num = this.left.length == 0 ? this.right.shift() : this.left.shift();
- this.rebalance();
- return num;
+FrontMiddleBackQueue.prototype.popFront = function () {
+ if (this.isEmpty()) return -1;
+ let num = this.left.length == 0 ? this.right.shift() : this.left.shift();
+ this.rebalance();
+ return num;
};
/**
* @return {number}
*/
-FrontMiddleBackQueue.prototype.popMiddle = function() {
- if (this.isEmpty()) return -1;
- let num = this.left.length == this.right.length ? this.left.pop() : this.right.shift();
- this.rebalance();
- return num;
+FrontMiddleBackQueue.prototype.popMiddle = function () {
+ if (this.isEmpty()) return -1;
+ let num =
+ this.left.length == this.right.length
+ ? this.left.pop()
+ : this.right.shift();
+ this.rebalance();
+ return num;
};
/**
* @return {number}
*/
-FrontMiddleBackQueue.prototype.popBack = function() {
- if (this.isEmpty()) return -1;
- let num = this.right.pop();
- this.rebalance();
- return num;
+FrontMiddleBackQueue.prototype.popBack = function () {
+ if (this.isEmpty()) return -1;
+ let num = this.right.pop();
+ this.rebalance();
+ return num;
};
FrontMiddleBackQueue.prototype.rebalance = function () {
- while (this.left.length > this.right.length) {
- this.right.unshift(this.left.pop());
- }
- while (this.right.length > this.left.length + 1) {
- this.left.push(this.right.shift());
- }
-}
+ while (this.left.length > this.right.length) {
+ this.right.unshift(this.left.pop());
+ }
+ while (this.right.length > this.left.length + 1) {
+ this.left.push(this.right.shift());
+ }
+};
FrontMiddleBackQueue.prototype.isEmpty = function () {
- return this.left.length == 0 && this.right.length == 0;
-}
+ return this.left.length == 0 && this.right.length == 0;
+};
/**
* Your FrontMiddleBackQueue object will be instantiated and called as such:
diff --git a/solution/1600-1699/1670.Design Front Middle Back Queue/Solution.py b/solution/1600-1699/1670.Design Front Middle Back Queue/Solution.py
index 8317e44cb0126..4450fc04d364d 100644
--- a/solution/1600-1699/1670.Design Front Middle Back Queue/Solution.py
+++ b/solution/1600-1699/1670.Design Front Middle Back Queue/Solution.py
@@ -1,8 +1,8 @@
class FrontMiddleBackQueue:
def __init__(self):
- self.left = collections.deque()
- self.right = collections.deque()
+ self.left = deque()
+ self.right = deque()
def pushFront(self, val: int) -> None:
self.left.appendleft(val)
diff --git a/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README.md b/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README.md
index 73fe9048618e1..a7d66f9c97a81 100644
--- a/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README.md
+++ b/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README.md
@@ -70,7 +70,7 @@
```python
class Solution:
def countStudents(self, students: List[int], sandwiches: List[int]) -> int:
- counter = collections.Counter(students)
+ counter = Counter(students)
for i, sandwich in enumerate(sandwiches):
if counter[sandwich] == 0:
return len(students) - i
diff --git a/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README_EN.md b/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README_EN.md
index 6ce35ad906259..83b2f77f02c85 100644
--- a/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README_EN.md
+++ b/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README_EN.md
@@ -61,7 +61,7 @@ Hence all students are able to eat.
```python
class Solution:
def countStudents(self, students: List[int], sandwiches: List[int]) -> int:
- counter = collections.Counter(students)
+ counter = Counter(students)
for i, sandwich in enumerate(sandwiches):
if counter[sandwich] == 0:
return len(students) - i
diff --git a/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/Solution.py b/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/Solution.py
index 81fdb89cbb195..28e3797ecdce9 100644
--- a/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/Solution.py
+++ b/solution/1700-1799/1700.Number of Students Unable to Eat Lunch/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def countStudents(self, students: List[int], sandwiches: List[int]) -> int:
- counter = collections.Counter(students)
+ counter = Counter(students)
for i, sandwich in enumerate(sandwiches):
if counter[sandwich] == 0:
return len(students) - i
diff --git a/solution/1700-1799/1705.Maximum Number of Eaten Apples/README.md b/solution/1700-1799/1705.Maximum Number of Eaten Apples/README.md
index 36cc6365da934..52e26289aa985 100644
--- a/solution/1700-1799/1705.Maximum Number of Eaten Apples/README.md
+++ b/solution/1700-1799/1705.Maximum Number of Eaten Apples/README.md
@@ -47,11 +47,12 @@
只有在 apples[i] = 0
时,days[i] = 0
才成立
-
## 解法
+优先队列。先吃掉最容易腐烂的苹果。
+
### **Python3**
@@ -59,7 +60,24 @@
```python
-
+class Solution:
+ def eatenApples(self, apples: List[int], days: List[int]) -> int:
+ q = []
+ n = len(apples)
+ i = ans = 0
+ while i < n or q:
+ if i < n and apples[i] > 0:
+ heappush(q, [i + days[i] - 1, apples[i]])
+ while q and q[0][0] < i:
+ heappop(q)
+ if q:
+ end, num = heappop(q)
+ num -= 1
+ ans += 1
+ if num > 0 and end > i:
+ heappush(q, [end, num])
+ i += 1
+ return ans
```
### **Java**
@@ -67,7 +85,58 @@
```java
+class Solution {
+ public int eatenApples(int[] apples, int[] days) {
+ PriorityQueue q = new PriorityQueue<>(Comparator.comparingInt(a -> a[0]));
+ int ans = 0, i = 0, n = apples.length;
+ while (i < n || !q.isEmpty()) {
+ if (i < n && apples[i] > 0) {
+ q.offer(new int[]{i + days[i] - 1, apples[i]});
+ }
+ while (!q.isEmpty() && q.peek()[0] < i) {
+ q.poll();
+ }
+ if (!q.isEmpty()) {
+ int[] t = q.poll();
+ if (--t[1] > 0 && t[0] > i) {
+ q.offer(t);
+ }
+ ++ans;
+ }
+ ++i;
+ }
+ return ans;
+ }
+}
+```
+### C++
+
+```cpp
+typedef pair PII;
+
+class Solution {
+public:
+ int eatenApples(vector& apples, vector& days) {
+ priority_queue, greater> q;
+ int i = 0, n = apples.size(), ans = 0;
+ while (i < n || !q.empty())
+ {
+ if (i < n && apples[i] > 0) q.emplace(i + days[i] - 1, apples[i]);
+ while (!q.empty() && q.top().first < i) q.pop();
+ if (!q.empty())
+ {
+ PII t = q.top();
+ q.pop();
+ --t.second;
+ ++ans;
+ if (t.second > 0 && t.first > i) q.emplace(t);
+ }
+ ++i;
+ }
+ return ans;
+ }
+};
```
### **...**
diff --git a/solution/1700-1799/1705.Maximum Number of Eaten Apples/README_EN.md b/solution/1700-1799/1705.Maximum Number of Eaten Apples/README_EN.md
index 69a95016fd277..bff4369da605b 100644
--- a/solution/1700-1799/1705.Maximum Number of Eaten Apples/README_EN.md
+++ b/solution/1700-1799/1705.Maximum Number of Eaten Apples/README_EN.md
@@ -45,7 +45,6 @@
days[i] = 0
if and only if apples[i] = 0
.
-
## Solutions
@@ -53,13 +52,81 @@
### **Python3**
```python
-
+class Solution:
+ def eatenApples(self, apples: List[int], days: List[int]) -> int:
+ q = []
+ n = len(apples)
+ i = ans = 0
+ while i < n or q:
+ if i < n and apples[i] > 0:
+ heappush(q, [i + days[i] - 1, apples[i]])
+ while q and q[0][0] < i:
+ heappop(q)
+ if q:
+ end, num = heappop(q)
+ num -= 1
+ ans += 1
+ if num > 0 and end > i:
+ heappush(q, [end, num])
+ i += 1
+ return ans
```
### **Java**
```java
+class Solution {
+ public int eatenApples(int[] apples, int[] days) {
+ PriorityQueue q = new PriorityQueue<>(Comparator.comparingInt(a -> a[0]));
+ int ans = 0, i = 0, n = apples.length;
+ while (i < n || !q.isEmpty()) {
+ if (i < n && apples[i] > 0) {
+ q.offer(new int[]{i + days[i] - 1, apples[i]});
+ }
+ while (!q.isEmpty() && q.peek()[0] < i) {
+ q.poll();
+ }
+ if (!q.isEmpty()) {
+ int[] t = q.poll();
+ if (--t[1] > 0 && t[0] > i) {
+ q.offer(t);
+ }
+ ++ans;
+ }
+ ++i;
+ }
+ return ans;
+ }
+}
+```
+### C++
+
+```cpp
+typedef pair PII;
+
+class Solution {
+public:
+ int eatenApples(vector& apples, vector& days) {
+ priority_queue, greater> q;
+ int i = 0, n = apples.size(), ans = 0;
+ while (i < n || !q.empty())
+ {
+ if (i < n && apples[i] > 0) q.emplace(i + days[i] - 1, apples[i]);
+ while (!q.empty() && q.top().first < i) q.pop();
+ if (!q.empty())
+ {
+ PII t = q.top();
+ q.pop();
+ --t.second;
+ ++ans;
+ if (t.second > 0 && t.first > i) q.emplace(t);
+ }
+ ++i;
+ }
+ return ans;
+ }
+};
```
### **...**
diff --git a/solution/1700-1799/1705.Maximum Number of Eaten Apples/Solution.cpp b/solution/1700-1799/1705.Maximum Number of Eaten Apples/Solution.cpp
new file mode 100644
index 0000000000000..7560571c0a20b
--- /dev/null
+++ b/solution/1700-1799/1705.Maximum Number of Eaten Apples/Solution.cpp
@@ -0,0 +1,24 @@
+typedef pair PII;
+
+class Solution {
+public:
+ int eatenApples(vector& apples, vector& days) {
+ priority_queue, greater> q;
+ int i = 0, n = apples.size(), ans = 0;
+ while (i < n || !q.empty())
+ {
+ if (i < n && apples[i] > 0) q.emplace(i + days[i] - 1, apples[i]);
+ while (!q.empty() && q.top().first < i) q.pop();
+ if (!q.empty())
+ {
+ PII t = q.top();
+ q.pop();
+ --t.second;
+ ++ans;
+ if (t.second > 0 && t.first > i) q.emplace(t);
+ }
+ ++i;
+ }
+ return ans;
+ }
+};
\ No newline at end of file
diff --git a/solution/1700-1799/1705.Maximum Number of Eaten Apples/Solution.java b/solution/1700-1799/1705.Maximum Number of Eaten Apples/Solution.java
new file mode 100644
index 0000000000000..36f980c3377c4
--- /dev/null
+++ b/solution/1700-1799/1705.Maximum Number of Eaten Apples/Solution.java
@@ -0,0 +1,23 @@
+class Solution {
+ public int eatenApples(int[] apples, int[] days) {
+ PriorityQueue q = new PriorityQueue<>(Comparator.comparingInt(a -> a[0]));
+ int ans = 0, i = 0, n = apples.length;
+ while (i < n || !q.isEmpty()) {
+ if (i < n && apples[i] > 0) {
+ q.offer(new int[]{i + days[i] - 1, apples[i]});
+ }
+ while (!q.isEmpty() && q.peek()[0] < i) {
+ q.poll();
+ }
+ if (!q.isEmpty()) {
+ int[] t = q.poll();
+ if (--t[1] > 0 && t[0] > i) {
+ q.offer(t);
+ }
+ ++ans;
+ }
+ ++i;
+ }
+ return ans;
+ }
+}
\ No newline at end of file
diff --git a/solution/1700-1799/1705.Maximum Number of Eaten Apples/Solution.py b/solution/1700-1799/1705.Maximum Number of Eaten Apples/Solution.py
new file mode 100644
index 0000000000000..d13de4c8a7dd6
--- /dev/null
+++ b/solution/1700-1799/1705.Maximum Number of Eaten Apples/Solution.py
@@ -0,0 +1,18 @@
+class Solution:
+ def eatenApples(self, apples: List[int], days: List[int]) -> int:
+ q = []
+ n = len(apples)
+ i = ans = 0
+ while i < n or q:
+ if i < n and apples[i] > 0:
+ heappush(q, [i + days[i] - 1, apples[i]])
+ while q and q[0][0] < i:
+ heappop(q)
+ if q:
+ end, num = heappop(q)
+ num -= 1
+ ans += 1
+ if num > 0 and end > i:
+ heappush(q, [end, num])
+ i += 1
+ return ans
\ No newline at end of file
diff --git a/solution/1700-1799/1711.Count Good Meals/README.md b/solution/1700-1799/1711.Count Good Meals/README.md
index a7e3fbb809642..d63dda196105d 100644
--- a/solution/1700-1799/1711.Count Good Meals/README.md
+++ b/solution/1700-1799/1711.Count Good Meals/README.md
@@ -41,7 +41,6 @@
0 <= deliciousness[i] <= 220
-
## 解法
用最暴力的方法枚举每对元素肯定会超时,可以用哈希表优化对**之前元素出现次数**的查询。
@@ -60,7 +59,7 @@ class Solution:
mod = 1000000007
limit = max(deliciousness) * 2
pairs = 0
- freq = collections.defaultdict(int)
+ freq = defaultdict(int)
for d in deliciousness:
target = 1
while target <= limit:
diff --git a/solution/1700-1799/1711.Count Good Meals/README_EN.md b/solution/1700-1799/1711.Count Good Meals/README_EN.md
index 5b174de449fe3..8e7a7268f5783 100644
--- a/solution/1700-1799/1711.Count Good Meals/README_EN.md
+++ b/solution/1700-1799/1711.Count Good Meals/README_EN.md
@@ -37,7 +37,6 @@ Their respective sums are 4, 8, 8, and 16, all of which are powers of 2.
0 <= deliciousness[i] <= 220
-
## Solutions
@@ -50,7 +49,7 @@ class Solution:
mod = 1000000007
limit = max(deliciousness) * 2
pairs = 0
- freq = collections.defaultdict(int)
+ freq = defaultdict(int)
for d in deliciousness:
target = 1
while target <= limit:
diff --git a/solution/1700-1799/1711.Count Good Meals/Solution.py b/solution/1700-1799/1711.Count Good Meals/Solution.py
index 2b9283e63232c..cd9bee59c3ab7 100644
--- a/solution/1700-1799/1711.Count Good Meals/Solution.py
+++ b/solution/1700-1799/1711.Count Good Meals/Solution.py
@@ -3,7 +3,7 @@ def countPairs(self, deliciousness: List[int]) -> int:
mod = 1000000007
limit = max(deliciousness) * 2
pairs = 0
- freq = collections.defaultdict(int)
+ freq = defaultdict(int)
for d in deliciousness:
target = 1
while target <= limit:
diff --git a/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README.md b/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README.md
index 4dd1e9819452d..ed644b59ee351 100644
--- a/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README.md
+++ b/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README.md
@@ -134,7 +134,7 @@ class Solution:
for i, j in allowedSwaps:
p[find(i)] = find(j)
- mp = collections.defaultdict(collections.Counter)
+ mp = defaultdict(Counter)
for i in range(n):
mp[find(i)][source[i]] += 1
res = 0
diff --git a/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README_EN.md b/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README_EN.md
index c3615601b9130..509d10e577c48 100644
--- a/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README_EN.md
+++ b/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/README_EN.md
@@ -73,7 +73,7 @@ class Solution:
for i, j in allowedSwaps:
p[find(i)] = find(j)
- mp = collections.defaultdict(collections.Counter)
+ mp = defaultdict(Counter)
for i in range(n):
mp[find(i)][source[i]] += 1
res = 0
diff --git a/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/Solution.py b/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/Solution.py
index 76291df0d2f9f..75de733a236a5 100644
--- a/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/Solution.py
+++ b/solution/1700-1799/1722.Minimize Hamming Distance After Swap Operations/Solution.py
@@ -11,7 +11,7 @@ def find(x):
for i, j in allowedSwaps:
p[find(i)] = find(j)
- mp = collections.defaultdict(collections.Counter)
+ mp = defaultdict(Counter)
for i in range(n):
mp[find(i)][source[i]] += 1
res = 0
diff --git a/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README.md b/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README.md
index c8ec86253ede5..654f0e073860b 100644
--- a/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README.md
+++ b/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README.md
@@ -54,7 +54,6 @@
题目数据保证存在一些以 adjacentPairs
作为元素对的数组 nums
-
## 解法
@@ -70,7 +69,7 @@
```python
class Solution:
def restoreArray(self, adjacentPairs: List[List[int]]) -> List[int]:
- graph = collections.defaultdict(list)
+ graph = defaultdict(list)
for pair in adjacentPairs:
graph[pair[0]].append(pair[1])
graph[pair[1]].append(pair[0])
diff --git a/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README_EN.md b/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README_EN.md
index b9b5c6b34622e..6bd68f5e425bd 100644
--- a/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README_EN.md
+++ b/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/README_EN.md
@@ -50,7 +50,6 @@ Another solution is [-3,1,4,-2], which would also be accepted.
There exists some nums
that has adjacentPairs
as its pairs.
-
## Solutions
Traverse the graph from the point where the degree is one.
@@ -62,7 +61,7 @@ Traverse the graph from the point where the degree is one.
```python
class Solution:
def restoreArray(self, adjacentPairs: List[List[int]]) -> List[int]:
- graph = collections.defaultdict(list)
+ graph = defaultdict(list)
for pair in adjacentPairs:
graph[pair[0]].append(pair[1])
graph[pair[1]].append(pair[0])
diff --git a/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/Solution.py b/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/Solution.py
index 9131e849ac139..f233c3ebb400d 100644
--- a/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/Solution.py
+++ b/solution/1700-1799/1743.Restore the Array From Adjacent Pairs/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def restoreArray(self, adjacentPairs: List[List[int]]) -> List[int]:
- graph = collections.defaultdict(list)
+ graph = defaultdict(list)
for pair in adjacentPairs:
graph[pair[0]].append(pair[1])
graph[pair[1]].append(pair[0])
diff --git a/solution/1700-1799/1772.Sort Features by Popularity/README.md b/solution/1700-1799/1772.Sort Features by Popularity/README.md
index 20360f69b9eaf..d4d77bf92b732 100644
--- a/solution/1700-1799/1772.Sort Features by Popularity/README.md
+++ b/solution/1700-1799/1772.Sort Features by Popularity/README.md
@@ -61,7 +61,7 @@
class Solution:
def sortFeatures(self, features: List[str], responses: List[str]) -> List[str]:
feature_set = set(features)
- counter = collections.Counter()
+ counter = Counter()
for resp in responses:
for feat in set(resp.split(' ')):
if feat in feature_set:
diff --git a/solution/1700-1799/1772.Sort Features by Popularity/README_EN.md b/solution/1700-1799/1772.Sort Features by Popularity/README_EN.md
index 9459eb91728a8..2ea342fc942d8 100644
--- a/solution/1700-1799/1772.Sort Features by Popularity/README_EN.md
+++ b/solution/1700-1799/1772.Sort Features by Popularity/README_EN.md
@@ -51,7 +51,7 @@
class Solution:
def sortFeatures(self, features: List[str], responses: List[str]) -> List[str]:
feature_set = set(features)
- counter = collections.Counter()
+ counter = Counter()
for resp in responses:
for feat in set(resp.split(' ')):
if feat in feature_set:
diff --git a/solution/1700-1799/1772.Sort Features by Popularity/Solution.py b/solution/1700-1799/1772.Sort Features by Popularity/Solution.py
index 2b81fe606a3ea..0b26ad4936d14 100644
--- a/solution/1700-1799/1772.Sort Features by Popularity/Solution.py
+++ b/solution/1700-1799/1772.Sort Features by Popularity/Solution.py
@@ -1,7 +1,7 @@
class Solution:
def sortFeatures(self, features: List[str], responses: List[str]) -> List[str]:
feature_set = set(features)
- counter = collections.Counter()
+ counter = Counter()
for resp in responses:
for feat in set(resp.split(' ')):
if feat in feature_set:
diff --git a/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README.md b/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README.md
index 78d7cd9693f7a..f60e5137a1ba8 100644
--- a/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README.md
+++ b/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README.md
@@ -8,12 +8,8 @@
Given the head
of a linked list, find all the values that appear more than once in the list and delete the nodes that have any of those values.
-
-
Return the linked list after the deletions.
-
-
Example 1:
@@ -30,8 +26,6 @@
-
-
Example 2:
@@ -46,8 +40,6 @@
-
-
Example 3:
@@ -62,14 +54,10 @@
-
-
Constraints:
-
-
- The number of nodes in the list is in the range
[1, 105]
1 <= Node.val <= 105
@@ -96,7 +84,7 @@
class Solution:
def deleteDuplicatesUnsorted(self, head: ListNode) -> ListNode:
cur = head
- counter = collections.Counter()
+ counter = Counter()
while cur:
counter[cur.val] += 1
cur = cur.next
diff --git a/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README_EN.md b/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README_EN.md
index 3445f7acf30ba..26b6d14cebea4 100644
--- a/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README_EN.md
+++ b/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/README_EN.md
@@ -76,7 +76,7 @@
class Solution:
def deleteDuplicatesUnsorted(self, head: ListNode) -> ListNode:
cur = head
- counter = collections.Counter()
+ counter = Counter()
while cur:
counter[cur.val] += 1
cur = cur.next
diff --git a/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/Solution.py b/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/Solution.py
index 15ce75a680097..4a393e4384dc0 100644
--- a/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/Solution.py
+++ b/solution/1800-1899/1836.Remove Duplicates From an Unsorted Linked List/Solution.py
@@ -6,7 +6,7 @@
class Solution:
def deleteDuplicatesUnsorted(self, head: ListNode) -> ListNode:
cur = head
- counter = collections.Counter()
+ counter = Counter()
while cur:
counter[cur.val] += 1
cur = cur.next
diff --git a/solution/1800-1899/1861.Rotating the Box/README.md b/solution/1800-1899/1861.Rotating the Box/README.md
index 9c5ff3ebfce46..a164448cc9211 100644
--- a/solution/1800-1899/1861.Rotating the Box/README.md
+++ b/solution/1800-1899/1861.Rotating the Box/README.md
@@ -90,7 +90,7 @@ class Solution:
for j in range(n):
res[j][m - i - 1] = box[i][j]
for j in range(m):
- q = collections.deque()
+ q = deque()
for i in range(n - 1, -1, -1):
if res[i][j] == '*':
q.clear()
diff --git a/solution/1800-1899/1861.Rotating the Box/README_EN.md b/solution/1800-1899/1861.Rotating the Box/README_EN.md
index 197f1c8cbc703..7432da55581bd 100644
--- a/solution/1800-1899/1861.Rotating the Box/README_EN.md
+++ b/solution/1800-1899/1861.Rotating the Box/README_EN.md
@@ -108,7 +108,7 @@ class Solution:
for j in range(n):
res[j][m - i - 1] = box[i][j]
for j in range(m):
- q = collections.deque()
+ q = deque()
for i in range(n - 1, -1, -1):
if res[i][j] == '*':
q.clear()
diff --git a/solution/1800-1899/1861.Rotating the Box/Solution.py b/solution/1800-1899/1861.Rotating the Box/Solution.py
index 6b75fd1f7ba9a..08b4c4ffe676c 100644
--- a/solution/1800-1899/1861.Rotating the Box/Solution.py
+++ b/solution/1800-1899/1861.Rotating the Box/Solution.py
@@ -6,7 +6,7 @@ def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]:
for j in range(n):
res[j][m - i - 1] = box[i][j]
for j in range(m):
- q = collections.deque()
+ q = deque()
for i in range(n - 1, -1, -1):
if res[i][j] == '*':
q.clear()
diff --git a/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README.md b/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README.md
index 72be7b082979c..59f610a1d8243 100644
--- a/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README.md
+++ b/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README.md
@@ -76,7 +76,7 @@ class FindSumPairs:
def __init__(self, nums1: List[int], nums2: List[int]):
self.nums1 = nums1
self.nums2 = nums2
- self.counter = collections.Counter(nums2)
+ self.counter = Counter(nums2)
def add(self, index: int, val: int) -> None:
old_val = self.nums2[index]
diff --git a/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README_EN.md b/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README_EN.md
index 2ec280dd6ae15..21b2d5dc3947c 100644
--- a/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README_EN.md
+++ b/solution/1800-1899/1865.Finding Pairs With a Certain Sum/README_EN.md
@@ -66,7 +66,7 @@ class FindSumPairs:
def __init__(self, nums1: List[int], nums2: List[int]):
self.nums1 = nums1
self.nums2 = nums2
- self.counter = collections.Counter(nums2)
+ self.counter = Counter(nums2)
def add(self, index: int, val: int) -> None:
old_val = self.nums2[index]
diff --git a/solution/1800-1899/1865.Finding Pairs With a Certain Sum/Solution.py b/solution/1800-1899/1865.Finding Pairs With a Certain Sum/Solution.py
index f71c29b779522..d0accd338f4da 100644
--- a/solution/1800-1899/1865.Finding Pairs With a Certain Sum/Solution.py
+++ b/solution/1800-1899/1865.Finding Pairs With a Certain Sum/Solution.py
@@ -3,7 +3,7 @@ class FindSumPairs:
def __init__(self, nums1: List[int], nums2: List[int]):
self.nums1 = nums1
self.nums2 = nums2
- self.counter = collections.Counter(nums2)
+ self.counter = Counter(nums2)
def add(self, index: int, val: int) -> None:
old_val = self.nums2[index]
diff --git a/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README.md b/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README.md
index 0502eaaa7da65..bbcba629fce63 100644
--- a/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README.md
+++ b/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README.md
@@ -40,7 +40,6 @@
words[i]
由小写英文字母组成
-
## 解法
@@ -54,7 +53,7 @@
```python
class Solution:
def makeEqual(self, words: List[str]) -> bool:
- counter = collections.Counter()
+ counter = Counter()
for word in words:
for c in word:
counter[c] += 1
@@ -90,21 +89,21 @@ class Solution {
```ts
function makeEqual(words: string[]): boolean {
- let n = words.length;
- let letters = new Array(26).fill(0);
- for (let word of words) {
- for (let i = 0; i < word.length; ++i) {
- ++letters[word.charCodeAt(i) - 97];
- }
+ let n = words.length;
+ let letters = new Array(26).fill(0);
+ for (let word of words) {
+ for (let i = 0; i < word.length; ++i) {
+ ++letters[word.charCodeAt(i) - 97];
}
+ }
- for (let i = 0; i < letters.length; ++i) {
- if (letters[i] % n != 0) {
- return false;
- }
+ for (let i = 0; i < letters.length; ++i) {
+ if (letters[i] % n != 0) {
+ return false;
}
- return true;
-};
+ }
+ return true;
+}
```
### **C++**
diff --git a/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README_EN.md b/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README_EN.md
index 02b3a898dd4e0..454d19a832a11 100644
--- a/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README_EN.md
+++ b/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README_EN.md
@@ -38,7 +38,6 @@ All the strings are now equal to "abc", so return true
.
words[i]
consists of lowercase English letters.
-
## Solutions
@@ -48,7 +47,7 @@ All the strings are now equal to "abc", so return true
.
```python
class Solution:
def makeEqual(self, words: List[str]) -> bool:
- counter = collections.Counter()
+ counter = Counter()
for word in words:
for c in word:
counter[c] += 1
@@ -82,21 +81,21 @@ class Solution {
```ts
function makeEqual(words: string[]): boolean {
- let n = words.length;
- let letters = new Array(26).fill(0);
- for (let word of words) {
- for (let i = 0; i < word.length; ++i) {
- ++letters[word.charCodeAt(i) - 97];
- }
+ let n = words.length;
+ let letters = new Array(26).fill(0);
+ for (let word of words) {
+ for (let i = 0; i < word.length; ++i) {
+ ++letters[word.charCodeAt(i) - 97];
}
+ }
- for (let i = 0; i < letters.length; ++i) {
- if (letters[i] % n != 0) {
- return false;
- }
+ for (let i = 0; i < letters.length; ++i) {
+ if (letters[i] % n != 0) {
+ return false;
}
- return true;
-};
+ }
+ return true;
+}
```
### **C++**
diff --git a/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/Solution.py b/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/Solution.py
index 231221375a012..d6648dbd82e6a 100644
--- a/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/Solution.py
+++ b/solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def makeEqual(self, words: List[str]) -> bool:
- counter = collections.Counter()
+ counter = Counter()
for word in words:
for c in word:
counter[c] += 1
diff --git a/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README.md b/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README.md
index 93f4ff0aed9ae..dc2ed6e87878d 100644
--- a/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README.md
+++ b/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README.md
@@ -65,7 +65,7 @@
class Solution:
def longestCommomSubsequence(self, arrays: List[List[int]]) -> List[int]:
n = len(arrays)
- counter = collections.defaultdict(int)
+ counter = defaultdict(int)
for array in arrays:
for e in array:
counter[e] += 1
diff --git a/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README_EN.md b/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README_EN.md
index 8d38488f8b209..ca9dfaa073521 100644
--- a/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README_EN.md
+++ b/solution/1900-1999/1940.Longest Common Subsequence Between Sorted Arrays/README_EN.md
@@ -57,7 +57,7 @@
class Solution:
def longestCommomSubsequence(self, arrays: List[List[int]]) -> List[int]:
n = len(arrays)
- counter = collections.defaultdict(int)
+ counter = defaultdict(int)
for array in arrays:
for e in array:
counter[e] += 1
diff --git a/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README.md b/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README.md
index ae1d30cd1f7d9..676fde5c895fa 100644
--- a/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README.md
+++ b/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README.md
@@ -36,7 +36,6 @@
s
只包含小写英文字母。
-
## 解法
@@ -50,7 +49,7 @@
```python
class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
- counter = collections.Counter(s)
+ counter = Counter(s)
cnt = -1
for c, times in counter.items():
if cnt == -1:
diff --git a/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README_EN.md b/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README_EN.md
index 5255de6f1b8e8..3175c7c7b157b 100644
--- a/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README_EN.md
+++ b/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/README_EN.md
@@ -34,7 +34,6 @@
s
consists of lowercase English letters.
-
## Solutions
@@ -44,7 +43,7 @@
```python
class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
- counter = collections.Counter(s)
+ counter = Counter(s)
cnt = -1
for c, times in counter.items():
if cnt == -1:
diff --git a/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/Solution.py b/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/Solution.py
index c76d3b49d7981..7b3d6c4a7ac73 100644
--- a/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/Solution.py
+++ b/solution/1900-1999/1941.Check if All Characters Have Equal Number of Occurrences/Solution.py
@@ -1,6 +1,6 @@
class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
- counter = collections.Counter(s)
+ counter = Counter(s)
cnt = -1
for c, times in counter.items():
if cnt == -1:
diff --git a/solution/1900-1999/1998.GCD Sort of an Array/README.md b/solution/1900-1999/1998.GCD Sort of an Array/README.md
index 60729e6db9e22..7947b3afb2a29 100644
--- a/solution/1900-1999/1998.GCD Sort of an Array/README.md
+++ b/solution/1900-1999/1998.GCD Sort of an Array/README.md
@@ -134,7 +134,7 @@ class Solution:
def gcdSort(self, nums: List[int]) -> bool:
n = 10 ** 5 + 10
p = list(range(n))
- f = collections.defaultdict(list)
+ f = defaultdict(list)
mx = max(nums)
for i in range(2, mx + 1):
if f[i]:
diff --git a/solution/1900-1999/1998.GCD Sort of an Array/README_EN.md b/solution/1900-1999/1998.GCD Sort of an Array/README_EN.md
index f1cfdfea675ee..452d4370060d8 100644
--- a/solution/1900-1999/1998.GCD Sort of an Array/README_EN.md
+++ b/solution/1900-1999/1998.GCD Sort of an Array/README_EN.md
@@ -50,7 +50,6 @@ We can sort [10,5,9,3,15] by performing the following operations:
2 <= nums[i] <= 105
-
## Solutions
Union find.
@@ -64,23 +63,23 @@ class Solution:
def gcdSort(self, nums: List[int]) -> bool:
n = 10 ** 5 + 10
p = list(range(n))
- f = collections.defaultdict(list)
+ f = defaultdict(list)
mx = max(nums)
for i in range(2, mx + 1):
if f[i]:
continue
for j in range(i, mx + 1, i):
f[j].append(i)
-
+
def find(x):
if p[x] != x:
p[x] = find(p[x])
return p[x]
-
+
for i in nums:
for j in f[i]:
p[find(i)] = find(j)
-
+
s = sorted(nums)
for i, num in enumerate(nums):
if s[i] != num and find(num) != find(s[i]):
diff --git a/solution/1900-1999/1998.GCD Sort of an Array/Solution.py b/solution/1900-1999/1998.GCD Sort of an Array/Solution.py
index e8a0bf66276cc..f8288cf22316a 100644
--- a/solution/1900-1999/1998.GCD Sort of an Array/Solution.py
+++ b/solution/1900-1999/1998.GCD Sort of an Array/Solution.py
@@ -2,23 +2,23 @@ class Solution:
def gcdSort(self, nums: List[int]) -> bool:
n = 10 ** 5 + 10
p = list(range(n))
- f = collections.defaultdict(list)
+ f = defaultdict(list)
mx = max(nums)
for i in range(2, mx + 1):
if f[i]:
continue
for j in range(i, mx + 1, i):
f[j].append(i)
-
+
def find(x):
if p[x] != x:
p[x] = find(p[x])
return p[x]
-
+
for i in nums:
for j in f[i]:
p[find(i)] = find(j)
-
+
s = sorted(nums)
for i, num in enumerate(nums):
if s[i] != num and find(num) != find(s[i]):
diff --git a/solution/2000-2099/2034.Stock Price Fluctuation/README.md b/solution/2000-2099/2034.Stock Price Fluctuation/README.md
index 7a0dfdb50263a..0ff69f27acf14 100644
--- a/solution/2000-2099/2034.Stock Price Fluctuation/README.md
+++ b/solution/2000-2099/2034.Stock Price Fluctuation/README.md
@@ -62,7 +62,6 @@ stockPrice.minimum(); // 返回 2 ,最低价格时间戳为 4 ,价格为
current
,maximum
和 minimum
被调用时,update
操作 至少 已经被调用过 一次 。
-
## 解法
@@ -81,19 +80,19 @@ class StockPrice:
self.mp = {}
self.mi = []
self.mx = []
- self.counter = collections.Counter()
+ self.counter = Counter()
def update(self, timestamp: int, price: int) -> None:
if timestamp in self.mp:
old_price = self.mp[timestamp]
self.counter[old_price] -= 1
-
+
self.mp[timestamp] = price
self.last_ts = max(self.last_ts, timestamp)
self.counter[price] += 1
heapq.heappush(self.mi, price)
heapq.heappush(self.mx, -price)
-
+
def current(self) -> int:
return self.mp[self.last_ts]
@@ -132,7 +131,7 @@ class StockPrice {
public StockPrice() {
}
-
+
public void update(int timestamp, int price) {
if (mp.containsKey(timestamp)) {
int oldPrice = mp.get(timestamp);
@@ -144,18 +143,18 @@ class StockPrice {
mi.offer(price);
mx.offer(price);
}
-
+
public int current() {
return mp.get(lastTs);
}
-
+
public int maximum() {
while (counter.getOrDefault(mx.peek(), 0) == 0) {
mx.poll();
}
return mx.peek();
}
-
+
public int minimum() {
while (counter.getOrDefault(mi.peek(), 0) == 0) {
mi.poll();
@@ -186,9 +185,9 @@ private:
unordered_map counter;
public:
StockPrice() {
-
+
}
-
+
void update(int timestamp, int price) {
if (mp.find(timestamp) != mp.end())
{
@@ -201,16 +200,16 @@ public:
mi.push(price);
mx.push(price);
}
-
+
int current() {
return mp[lastTs];
}
-
+
int maximum() {
while (!counter[mx.top()]) mx.pop();
return mx.top();
}
-
+
int minimum() {
while (!counter[mi.top()]) mi.pop();
return mi.top();
diff --git a/solution/2000-2099/2034.Stock Price Fluctuation/README_EN.md b/solution/2000-2099/2034.Stock Price Fluctuation/README_EN.md
index f4b96d9d900ae..48cff4370423a 100644
--- a/solution/2000-2099/2034.Stock Price Fluctuation/README_EN.md
+++ b/solution/2000-2099/2034.Stock Price Fluctuation/README_EN.md
@@ -73,19 +73,19 @@ class StockPrice:
self.mp = {}
self.mi = []
self.mx = []
- self.counter = collections.Counter()
+ self.counter = Counter()
def update(self, timestamp: int, price: int) -> None:
if timestamp in self.mp:
old_price = self.mp[timestamp]
self.counter[old_price] -= 1
-
+
self.mp[timestamp] = price
self.last_ts = max(self.last_ts, timestamp)
self.counter[price] += 1
heapq.heappush(self.mi, price)
heapq.heappush(self.mx, -price)
-
+
def current(self) -> int:
return self.mp[self.last_ts]
@@ -122,7 +122,7 @@ class StockPrice {
public StockPrice() {
}
-
+
public void update(int timestamp, int price) {
if (mp.containsKey(timestamp)) {
int oldPrice = mp.get(timestamp);
@@ -134,18 +134,18 @@ class StockPrice {
mi.offer(price);
mx.offer(price);
}
-
+
public int current() {
return mp.get(lastTs);
}
-
+
public int maximum() {
while (counter.getOrDefault(mx.peek(), 0) == 0) {
mx.poll();
}
return mx.peek();
}
-
+
public int minimum() {
while (counter.getOrDefault(mi.peek(), 0) == 0) {
mi.poll();
@@ -176,9 +176,9 @@ private:
unordered_map counter;
public:
StockPrice() {
-
+
}
-
+
void update(int timestamp, int price) {
if (mp.find(timestamp) != mp.end())
{
@@ -191,16 +191,16 @@ public:
mi.push(price);
mx.push(price);
}
-
+
int current() {
return mp[lastTs];
}
-
+
int maximum() {
while (!counter[mx.top()]) mx.pop();
return mx.top();
}
-
+
int minimum() {
while (!counter[mi.top()]) mi.pop();
return mi.top();
diff --git a/solution/2000-2099/2034.Stock Price Fluctuation/Solution.py b/solution/2000-2099/2034.Stock Price Fluctuation/Solution.py
index 43030dd60c118..d5f39ef903a14 100644
--- a/solution/2000-2099/2034.Stock Price Fluctuation/Solution.py
+++ b/solution/2000-2099/2034.Stock Price Fluctuation/Solution.py
@@ -5,19 +5,18 @@ def __init__(self):
self.mp = {}
self.mi = []
self.mx = []
- self.counter = collections.Counter()
+ self.counter = Counter()
def update(self, timestamp: int, price: int) -> None:
if timestamp in self.mp:
old_price = self.mp[timestamp]
self.counter[old_price] -= 1
-
+
self.mp[timestamp] = price
self.last_ts = max(self.last_ts, timestamp)
self.counter[price] += 1
heapq.heappush(self.mi, price)
heapq.heappush(self.mx, -price)
-
def current(self) -> int:
return self.mp[self.last_ts]
@@ -38,4 +37,4 @@ def minimum(self) -> int:
# obj.update(timestamp,price)
# param_2 = obj.current()
# param_3 = obj.maximum()
-# param_4 = obj.minimum()
\ No newline at end of file
+# param_4 = obj.minimum()
diff --git a/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README.md b/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README.md
index e476c6712a858..f52045a41a53e 100644
--- a/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README.md
+++ b/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README.md
@@ -64,8 +64,8 @@
class Solution:
def minimumDifference(self, nums: List[int]) -> int:
n = len(nums) >> 1
- f = collections.defaultdict(set)
- g = collections.defaultdict(set)
+ f = defaultdict(set)
+ g = defaultdict(set)
for i in range(1 << n):
s = cnt = 0
s1 = cnt1 = 0
diff --git a/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README_EN.md b/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README_EN.md
index 9c29714b7eea6..c7eac8abeb3bf 100644
--- a/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README_EN.md
+++ b/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/README_EN.md
@@ -55,8 +55,8 @@ The absolute difference between the sums of the arrays is abs((2 + 4 + -9) - (-1
class Solution:
def minimumDifference(self, nums: List[int]) -> int:
n = len(nums) >> 1
- f = collections.defaultdict(set)
- g = collections.defaultdict(set)
+ f = defaultdict(set)
+ g = defaultdict(set)
for i in range(1 << n):
s = cnt = 0
s1 = cnt1 = 0
diff --git a/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/Solution.py b/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/Solution.py
index 94529e27cb45a..dfbde532d40d6 100644
--- a/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/Solution.py
+++ b/solution/2000-2099/2035.Partition Array Into Two Arrays to Minimize Sum Difference/Solution.py
@@ -1,8 +1,8 @@
class Solution:
def minimumDifference(self, nums: List[int]) -> int:
n = len(nums) >> 1
- f = collections.defaultdict(set)
- g = collections.defaultdict(set)
+ f = defaultdict(set)
+ g = defaultdict(set)
for i in range(1 << n):
s = cnt = 0
s1 = cnt1 = 0