We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a502841 commit c69b910Copy full SHA for c69b910
0162_find_peak_element/peak.c
@@ -1,14 +1,15 @@
1
#include <stdio.h>
2
#include <stdlib.h>
3
4
-static int findPeakElement(int* nums, int numsSize)
5
-{
6
- if (numsSize == 1) {
7
- return nums[0];
8
- }
9
+int findPeakElement(int* nums, int numsSize)
+{
10
int i;
11
- for (i = 1; i < numsSize && nums[i] > nums[i - 1]; i++) {}
+ for (i = 1; i < numsSize; i++) {
+ if (nums[i] < nums[i - 1]) {
+ break;
+ }
12
13
return i - 1;
14
}
15
0162_find_peak_element/peak.cc
@@ -0,0 +1,16 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+class Solution {
+public:
+ int findPeakElement(vector<int>& nums) {
+ int i;
+ for (i = 1; i < nums.size(); i++) {
+ return i - 1;
16
+};
0 commit comments