Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Oct 27, 2024. It is now read-only.

Commit 763a752

Browse files
authored
Merge branch 'd-coder111:main' into main
2 parents a6740b3 + 6419add commit 763a752

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

‎C++/FindPeakElement.cpp‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int findPeakElement(int arr[], int n)
5+
{
6+
int start = 0;
7+
int end = n - 1;
8+
while (start < end)
9+
{
10+
int mid = start + (end - start) / 2;
11+
if (arr[mid] > arr[mid + 1])
12+
{
13+
end = mid;
14+
}
15+
else
16+
{
17+
start = mid + 1;
18+
}
19+
}
20+
return start;
21+
}
22+
23+
int main()
24+
{
25+
int arr[] = {1000, 11, 445, 1, 330, 3000};
26+
int n = sizeof(arr) / sizeof(arr[0]);
27+
int ans = findPeakElement(arr, n);
28+
cout << "Index of the peak element of array [ 1000, 11, 445, 1, 330, 3000 ] is " << ans;
29+
}

‎JAVA/FindPeakElement.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//Link:-https://leetcode.com/problems/find-peak-element/
22

3-
class Main {
3+
class FindPeakElement {
44
public static int findPeakElement(int[] arr) {
55
int start = 0;
66
int end = arr.length - 1;
@@ -18,6 +18,6 @@ public static int findPeakElement(int[] arr) {
1818
public static void main(String[] args) {
1919
int arr[] = { 1000, 11, 445, 1, 330, 3000 };
2020
int ans = findPeakElement(arr);
21-
System.out.println("Peak element is " + ans);
21+
System.out.println("Index of the peak element of array [ 1000, 11, 445, 1, 330, 3000 ] is " + ans);
2222
}
2323
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /