Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int peakIndexInMountainArray(vector<int>& A) {
- int l = 1, r = A.size() - 1, mid, ans;
- while (l <= r) {
- mid = (l + r) >> 1;
- if (A[mid] > A[mid - 1]) {
- ans = mid, l = mid + 1;
- }
- else
- r = mid - 1;
- }
- return ans;
- }
- };
- //O(log(A.size()) - time complexity, O(A.size()) - memory complexity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement