File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed
1287. Element Appearing More Than 25% In Sorted Array Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change
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
+ ```
Original file line number Diff line number Diff line change
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
+ } ;
Original file line number Diff line number Diff line change 1554
1554
│ └── Solution.cpp
1555
1555
├── 1278.Palindrome Partitioning III
1556
1556
│ └── Solution.cpp
1557
+ ├── 1287.Element Appearing More Than 25% In Sorted Array
1558
+ │ └── Solution.js
1557
1559
├── 5075.Number of Submatrices That Sum to Target
1558
1560
│ └── Solution.py
1559
1561
├── 5076.Greatest Common Divisor of Strings
1571
1573
├── 5087.Letter Tile Possibilities
1572
1574
│ └── Solution.py
1573
1575
└── README.md
1574
- ```
1576
+ ```
You can’t perform that action at this time.
0 commit comments