Skip to content

Commit 2c77ad7

Browse files
committed
feat: add solutions to lc problem: No.1502. Can Make Arithmetic Progression From Sequence
1 parent 3c450cb commit 2c77ad7

File tree

7 files changed

+55
-11
lines changed

7 files changed

+55
-11
lines changed

solution/1500-1599/1500.Design a File Sharing System/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ fileSharing.join([]); // 一个不拥有任何文件块的用户加入系
9191
<!-- 这里可写当前语言的特殊实现逻辑 -->
9292

9393
```python
94-
import queue
95-
9694
class FileSharing:
9795

9896
def __init__(self, m: int):

solution/1500-1599/1500.Design a File Sharing System/README_EN.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ fileSharing.join([]); // A user who doesn&#39;t have any chunks joined th
134134
### **Python3**
135135

136136
```python
137-
import queue
138-
139137
class FileSharing:
140138

141139
def __init__(self, m: int):

solution/1500-1599/1500.Design a File Sharing System/Solution.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import queue
2-
31
class FileSharing:
42

53
def __init__(self, m: int):
@@ -36,4 +34,4 @@ def request(self, userID: int, chunkID: int) -> List[int]:
3634
# obj = FileSharing(m)
3735
# param_1 = obj.join(ownedChunks)
3836
# obj.leave(userID)
39-
# param_3 = obj.request(userID,chunkID)
37+
# param_3 = obj.request(userID,chunkID)

solution/1500-1599/1502.Can Make Arithmetic Progression From Sequence/README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,31 @@
4949
<!-- 这里可写当前语言的特殊实现逻辑 -->
5050

5151
```python
52-
52+
class Solution:
53+
def canMakeArithmeticProgression(self, arr: List[int]) -> bool:
54+
arr.sort()
55+
for i in range(1, len(arr) - 1):
56+
if (arr[i] << 1) != arr[i - 1] + arr[i + 1]:
57+
return False
58+
return True
5359
```
5460

5561
### **Java**
5662

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

5965
```java
60-
66+
class Solution {
67+
public boolean canMakeArithmeticProgression(int[] arr) {
68+
Arrays.sort(arr);
69+
for (int i = 1; i < arr.length - 1; ++i) {
70+
if ((arr[i] << 1) != arr[i - 1] + arr[i + 1]) {
71+
return false;
72+
}
73+
}
74+
return true;
75+
}
76+
}
6177
```
6278

6379
### **...**

solution/1500-1599/1502.Can Make Arithmetic Progression From Sequence/README_EN.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,29 @@
4141
### **Python3**
4242

4343
```python
44-
44+
class Solution:
45+
def canMakeArithmeticProgression(self, arr: List[int]) -> bool:
46+
arr.sort()
47+
for i in range(1, len(arr) - 1):
48+
if (arr[i] << 1) != arr[i - 1] + arr[i + 1]:
49+
return False
50+
return True
4551
```
4652

4753
### **Java**
4854

4955
```java
50-
56+
class Solution {
57+
public boolean canMakeArithmeticProgression(int[] arr) {
58+
Arrays.sort(arr);
59+
for (int i = 1; i < arr.length - 1; ++i) {
60+
if ((arr[i] << 1) != arr[i - 1] + arr[i + 1]) {
61+
return false;
62+
}
63+
}
64+
return true;
65+
}
66+
}
5167
```
5268

5369
### **...**
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public boolean canMakeArithmeticProgression(int[] arr) {
3+
Arrays.sort(arr);
4+
for (int i = 1; i < arr.length - 1; ++i) {
5+
if ((arr[i] << 1) != arr[i - 1] + arr[i + 1]) {
6+
return false;
7+
}
8+
}
9+
return true;
10+
}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def canMakeArithmeticProgression(self, arr: List[int]) -> bool:
3+
arr.sort()
4+
for i in range(1, len(arr) - 1):
5+
if (arr[i] << 1) != arr[i - 1] + arr[i + 1]:
6+
return False
7+
return True

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy