Skip to content

Commit ca25a97

Browse files
solves peak index in mountain array
1 parent 3028683 commit ca25a97

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@
229229
| 840 | [Magic Squares in Grid](https://leetcode.com/problems/magic-squares-in-grid) | |
230230
| 844 | [Backspace String Compare](https://leetcode.com/problems/backspace-string-compare) | [![Java](assets/java.png)](src/BackspaceStringCompare.java) |
231231
| 849 | [Maximize Distance to Closest Person](https://leetcode.com/problems/maximize-distance-to-closest-person) | |
232-
| 852 | [Peak Index in Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array) | |
232+
| 852 | [Peak Index in Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array) | [![Java](assets/java.png)](src/PeakIndexInMountainArray.java) |
233233
| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings) | |
234234
| 860 | [Lemonade Change](https://leetcode.com/problems/lemonade-change) | |
235235
| 867 | [Transpose Matrix](https://leetcode.com/problems/transpose-matrix) | |

Diff for: src/PeakIndexInMountainArray.java

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class PeakIndexInMountainArray {
2+
public int peakIndexInMountainArray(int[] arr) {
3+
for (int index = 1 ; index < arr.length ; index++) {
4+
if (arr[index] < arr[index - 1]) return index - 1;
5+
}
6+
return -1;
7+
}
8+
}

0 commit comments

Comments
 (0)