Skip to content

Commit

Permalink
Time: 2 ms (80%), Space: 45.6 MB (14.51%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-S-Sahu committed Oct 30, 2024
1 parent a748022 commit c6b386f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 0941-valid-mountain-array/0941-valid-mountain-array.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution {
public boolean validMountainArray(int[] arr) {
if (arr.length < 3) return false;
int left = 0;
int right = arr.length - 1;

while (left < arr.length - 2 && arr[left] < arr[left + 1]) left++;
while (right > 0 && arr[right] < arr[right - 1]) right--;

return left == right && left != 0 && right != arr.length - 1;
}
}

0 comments on commit c6b386f

Please sign in to comment.