-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1464.数组中两元素的最大乘积.c
More file actions
52 lines (34 loc) · 1.02 KB
/
1464.数组中两元素的最大乘积.c
File metadata and controls
52 lines (34 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* @lc app=leetcode.cn id=1464 lang=c
*
* [1464] 数组中两元素的最大乘积
*/
// @lc code=start
int maxProduct(int* nums, int numsSize){
int firstMaxValue = 0;
int secondMaxValue = 0;
for (int *numsPointer = nums; numsPointer < (nums + numsSize); numsPointer++) {
if ((*numsPointer) >= firstMaxValue) {
secondMaxValue = firstMaxValue;
firstMaxValue = (*numsPointer);
// printf ("%d, %d, ", firstMaxValue, secondMaxValue);
}
else if ((*numsPointer) > secondMaxValue) {
secondMaxValue = (*numsPointer);
}
}
return ((firstMaxValue - 1) * (secondMaxValue - 1));
/*
int maximum = 0;
for (int i = 0; i < numsSize; i++) {
for (int j = (i + 1); j < numsSize; j++) {
int middle = ((nums[i] - 1) * (nums[j] - 1));
if (maximum < middle) {
maximum = middle;
}
}
}
return maximum;
*/
}
// @lc code=end