Skip to content

Commit f60c574

Browse files
committed
feat: add python3 solution for problem 1287
1 parent 5dd477f commit f60c574

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

solution/1287.Element Appearing More Than 25% In Sorted Array/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
## 1287. 有序数组中出现次数超过 25% 的元素
2+
### 题目描述
23
给你一个非递减的 有序 整数数组,已知这个数组中恰好有一个整数,它的出现次数超过数组元素总数的 25%。
34

45
请你找到并返回这个整数。
56

7+
### 代码实现
68
- JavaScript
79

810
```javascript
@@ -38,4 +40,16 @@ class Solution {
3840
return 0;
3941
}
4042
}
43+
```
44+
45+
- Python
46+
47+
```python
48+
class Solution:
49+
def findSpecialInteger(self, arr: List[int]) -> int:
50+
total = len(arr)
51+
for i, val in enumerate(arr):
52+
if val == arr[i + (total >> 2)]:
53+
return val
54+
return 0
4155
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def findSpecialInteger(self, arr: List[int]) -> int:
3+
total = len(arr)
4+
for i, val in enumerate(arr):
5+
if val == arr[i + (total >> 2)]:
6+
return val
7+
return 0

0 commit comments

Comments
 (0)