Skip to content

1287. Element Appearing More Than 25% In Sorted Array #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1287. Element Appearing More Than 25% In Sorted Array

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.

```Javascript
const findSpecialInteger = function(arr) {
let count = 0;
let item = -1;
for (var i = 0; i < arr.length; i++) {
if (item == arr[i]) {
count++;
} else {
item = arr[i];
count = 1;
}
if (count > arr.length * 0.25) {
return item;
}
}
return item;
};
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const findSpecialInteger = function(arr) {
let count = 0;
let item = -1;
for (var i = 0; i < arr.length; i++) {
if (item == arr[i]) {
count++;
} else {
item = arr[i];
count = 1;
}
if (count > arr.length * 0.25) {
return item;
}
}
return item;
};
4 changes: 3 additions & 1 deletion solution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,8 @@
│   └── Solution.cpp
├── 1278.Palindrome Partitioning III
│   └── Solution.cpp
├── 1287.Element Appearing More Than 25% In Sorted Array
│   └── Solution.js
├── 5075.Number of Submatrices That Sum to Target
│   └── Solution.py
├── 5076.Greatest Common Divisor of Strings
Expand All @@ -1571,4 +1573,4 @@
├── 5087.Letter Tile Possibilities
│   └── Solution.py
└── README.md
```
```