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 2e1aafb

Browse files
Merge pull request doocs#246 from Gapur/master
1287. Element Appearing More Than 25% In Sorted Array
2 parents 9d631e5 + 5eb6272 commit 2e1aafb

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
1287. Element Appearing More Than 25% In Sorted Array
2+
3+
Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time.
4+
5+
```Javascript
6+
const findSpecialInteger = function(arr) {
7+
let count = 0;
8+
let item = -1;
9+
for (var i = 0; i < arr.length; i++) {
10+
if (item == arr[i]) {
11+
count++;
12+
} else {
13+
item = arr[i];
14+
count = 1;
15+
}
16+
if (count > arr.length * 0.25) {
17+
return item;
18+
}
19+
}
20+
return item;
21+
};
22+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const findSpecialInteger = function(arr) {
2+
let count = 0;
3+
let item = -1;
4+
for (var i = 0; i < arr.length; i++) {
5+
if (item == arr[i]) {
6+
count++;
7+
} else {
8+
item = arr[i];
9+
count = 1;
10+
}
11+
if (count > arr.length * 0.25) {
12+
return item;
13+
}
14+
}
15+
return item;
16+
};

β€Žsolution/README.mdβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,8 @@
15541554
β”‚ └── Solution.cpp
15551555
β”œβ”€β”€ 1278.Palindrome Partitioning III
15561556
β”‚ └── Solution.cpp
1557+
β”œβ”€β”€ 1287.Element Appearing More Than 25% In Sorted Array
1558+
β”‚ └── Solution.js
15571559
β”œβ”€β”€ 5075.Number of Submatrices That Sum to Target
15581560
β”‚ └── Solution.py
15591561
β”œβ”€β”€ 5076.Greatest Common Divisor of Strings
@@ -1571,4 +1573,4 @@
15711573
β”œβ”€β”€ 5087.Letter Tile Possibilities
15721574
β”‚ └── Solution.py
15731575
└── README.md
1574-
```
1576+
```

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /