Skip to content

Commit 15001cc

Browse files
committed
feat: add solutions to lc problems
* No.2273.Find Resultant Array After Removing Anagrams * No.2274.Maximum Consecutive Floors Without Special Floors * No.2275.Largest Combination With Bitwise AND Greater Than Zero * No.2276.Count Integers in Intervals
1 parent 6b05a90 commit 15001cc

File tree

13 files changed

+408
-7
lines changed

13 files changed

+408
-7
lines changed

solution/1300-1399/1377.Frog Position After T Seconds/Solution.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
class Solution:
2-
def frogPosition(self, n: int, edges: List[List[int]], t: int, target: int) -> float:
2+
def frogPosition(
3+
self, n: int, edges: List[List[int]], t: int, target: int
4+
) -> float:
35
g = defaultdict(list)
46
for u, v in edges:
57
g[u].append(v)

solution/2200-2299/2273.Find Resultant Array After Removing Anagrams/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ words 中不存在互为字母异位词的两个相邻字符串,所以无需
6565
<!-- 这里可写当前语言的特殊实现逻辑 -->
6666

6767
```python
68-
68+
class Solution:
69+
def removeAnagrams(self, words: List[str]) -> List[str]:
70+
return [w for i, w in enumerate(words) if i == 0 or sorted(w) != sorted(words[i - 1])]
6971
```
7072

7173
### **Java**

solution/2200-2299/2273.Find Resultant Array After Removing Anagrams/README_EN.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ No two adjacent strings in words are anagrams of each other, so no operations ar
5252
### **Python3**
5353

5454
```python
55-
55+
class Solution:
56+
def removeAnagrams(self, words: List[str]) -> List[str]:
57+
return [w for i, w in enumerate(words) if i == 0 or sorted(w) != sorted(words[i - 1])]
5658
```
5759

5860
### **Java**
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def removeAnagrams(self, words: List[str]) -> List[str]:
3+
return [
4+
w
5+
for i, w in enumerate(words)
6+
if i == 0 or sorted(w) != sorted(words[i - 1])
7+
]

solution/2200-2299/2274.Maximum Consecutive Floors Without Special Floors/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@
5555
<!-- 这里可写当前语言的特殊实现逻辑 -->
5656

5757
```python
58-
58+
class Solution:
59+
def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:
60+
special.sort()
61+
ans = max(special[0] - bottom, top - special[-1])
62+
for i in range(1, len(special)):
63+
ans = max(ans, special[i] - special[i - 1] - 1)
64+
return ans
5965
```
6066

6167
### **Java**

solution/2200-2299/2274.Maximum Consecutive Floors Without Special Floors/README_EN.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ Therefore, we return the maximum number which is 3 floors.
4747
### **Python3**
4848

4949
```python
50-
50+
class Solution:
51+
def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:
52+
special.sort()
53+
ans = max(special[0] - bottom, top - special[-1])
54+
for i in range(1, len(special)):
55+
ans = max(ans, special[i] - special[i - 1] - 1)
56+
return ans
5157
```
5258

5359
### **Java**
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:
3+
special.sort()
4+
ans = max(special[0] - bottom, top - special[-1])
5+
for i in range(1, len(special)):
6+
ans = max(ans, special[i] - special[i - 1] - 1)
7+
return ans

solution/2200-2299/2275.Largest Combination With Bitwise AND Greater Than Zero/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,26 @@
5353

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

56+
**方法一:位运算**
57+
58+
大于 0,实际上就是要求存在某个二进制位(0-31),满足所有数字的这一位均为 1。
59+
5660
<!-- tabs:start -->
5761

5862
### **Python3**
5963

6064
<!-- 这里可写当前语言的特殊实现逻辑 -->
6165

6266
```python
63-
67+
class Solution:
68+
def largestCombination(self, candidates: List[int]) -> int:
69+
ans = 0
70+
for i in range(32):
71+
t = 0
72+
for x in candidates:
73+
t += (x >> i) & 1
74+
ans = max(ans, t)
75+
return ans
6476
```
6577

6678
### **Java**

solution/2200-2299/2275.Largest Combination With Bitwise AND Greater Than Zero/README_EN.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,15 @@ The size of the combination is 2, so we return 2.
5252
### **Python3**
5353

5454
```python
55-
55+
class Solution:
56+
def largestCombination(self, candidates: List[int]) -> int:
57+
ans = 0
58+
for i in range(32):
59+
t = 0
60+
for x in candidates:
61+
t += (x >> i) & 1
62+
ans = max(ans, t)
63+
return ans
5664
```
5765

5866
### **Java**
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def largestCombination(self, candidates: List[int]) -> int:
3+
ans = 0
4+
for i in range(32):
5+
t = 0
6+
for x in candidates:
7+
t += (x >> i) & 1
8+
ans = max(ans, t)
9+
return ans

0 commit comments

Comments
 (0)