We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 32473f8 commit b1e31afCopy full SHA for b1e31af
162_find_peak_element/Makefile
@@ -0,0 +1,2 @@
1
+all:
2
+ gcc -O2 -o test peak.c
162_find_peak_element/peak.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdlib.h>
3
+
4
+static int findPeakElement(int* nums, int numsSize)
5
+{
6
+ if (numsSize == 1) {
7
+ return nums[0];
8
+ }
9
10
+ int i;
11
+ for (i = 1; i < numsSize && nums[i] > nums[i - 1]; i++) {}
12
+ return i - 1;
13
+}
14
15
+int main(int argc, char **argv)
16
17
+ int i, count = argc - 1;
18
+ int *nums = malloc(count * sizeof(int));
19
+ for (i = 0; i < count; i++) {
20
+ nums[i] = atoi(argv[i + 1]);
21
22
+ printf("%d\n", findPeakElement(nums, count));
23
+ return 0;
24
0 commit comments