Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5dd477f

Browse files
committed
fix: rename folder and add java solution for problem 1287
See doocs#246 for detail.
1 parent 2e1aafb commit 5dd477f

File tree

4 files changed

+52
-22
lines changed

4 files changed

+52
-22
lines changed

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

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## 1287. 有序数组中出现次数超过 25% 的元素
2+
给你一个非递减的 有序 整数数组,已知这个数组中恰好有一个整数,它的出现次数超过数组元素总数的 25%。
3+
4+
请你找到并返回这个整数。
5+
6+
- JavaScript
7+
8+
```javascript
9+
const findSpecialInteger = function(arr) {
10+
let count = 0;
11+
let item = -1;
12+
for (var i = 0; i < arr.length; i++) {
13+
if (item == arr[i]) {
14+
count++;
15+
} else {
16+
item = arr[i];
17+
count = 1;
18+
}
19+
if (count > arr.length * 0.25) {
20+
return item;
21+
}
22+
}
23+
return item;
24+
};
25+
```
26+
27+
- Java
28+
29+
```java
30+
class Solution {
31+
public int findSpecialInteger(int[] arr) {
32+
int total = arr.length;
33+
for (int i = 0; i < total; ++i) {
34+
if (arr[i] == arr[i + (total >> 2)]) {
35+
return arr[i];
36+
}
37+
}
38+
return 0;
39+
}
40+
}
41+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int findSpecialInteger(int[] arr) {
3+
int total = arr.length;
4+
for (int i = 0; i < total; ++i) {
5+
if (arr[i] == arr[i + (total >> 2)]) {
6+
return arr[i];
7+
}
8+
}
9+
return 0;
10+
}
11+
}
File renamed without changes.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /