File tree 6 files changed +84
-0
lines changed
solution/1900-1999/1913.Maximum Product Difference Between Two Pairs
6 files changed +84
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,21 @@ var sumNums = function (n) {
60
60
};
61
61
```
62
62
63
+ ### ** Go**
64
+
65
+ ``` go
66
+ func sumNums (n int ) int {
67
+ s := 0
68
+ var sum func (int ) bool
69
+ sum = func (n int ) bool {
70
+ s += n
71
+ return n > 0 && sum (n-1 )
72
+ }
73
+ sum (n)
74
+ return s
75
+ }
76
+ ```
77
+
63
78
### ** ...**
64
79
65
80
```
Original file line number Diff line number Diff line change
1
+ func sumNums (n int ) int {
2
+ s := 0
3
+ var sum func (int ) bool
4
+ sum = func (n int ) bool {
5
+ s += n
6
+ return n > 0 && sum (n - 1 )
7
+ }
8
+ sum (n )
9
+ return s
10
+ }
Original file line number Diff line number Diff line change @@ -90,6 +90,29 @@ var maxProductDifference = function(nums) {
90
90
};
91
91
```
92
92
93
+ ### ** C++**
94
+
95
+ ``` cpp
96
+ class Solution {
97
+ public:
98
+ int maxProductDifference(vector<int >& nums) {
99
+ sort(nums.begin(), nums.end());
100
+ int n = nums.size();
101
+ return nums[ n - 1] * nums[ n - 2] - nums[ 0] * nums[ 1] ;
102
+ }
103
+ };
104
+ ```
105
+
106
+ ### **Go**
107
+
108
+ ```go
109
+ func maxProductDifference(nums []int) int {
110
+ sort.Ints(nums)
111
+ n := len(nums)
112
+ return nums[n-1]*nums[n-2] - nums[0]*nums[1]
113
+ }
114
+ ```
115
+
93
116
### ** ...**
94
117
95
118
```
Original file line number Diff line number Diff line change @@ -111,6 +111,29 @@ var maxProductDifference = function(nums) {
111
111
};
112
112
```
113
113
114
+ ### ** C++**
115
+
116
+ ``` cpp
117
+ class Solution {
118
+ public:
119
+ int maxProductDifference(vector<int >& nums) {
120
+ sort(nums.begin(), nums.end());
121
+ int n = nums.size();
122
+ return nums[ n - 1] * nums[ n - 2] - nums[ 0] * nums[ 1] ;
123
+ }
124
+ };
125
+ ```
126
+
127
+ ### **Go**
128
+
129
+ ```go
130
+ func maxProductDifference(nums []int) int {
131
+ sort.Ints(nums)
132
+ n := len(nums)
133
+ return nums[n-1]*nums[n-2] - nums[0]*nums[1]
134
+ }
135
+ ```
136
+
114
137
### ** ...**
115
138
116
139
```
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ int maxProductDifference (vector<int >& nums) {
4
+ sort (nums.begin (), nums.end ());
5
+ int n = nums.size ();
6
+ return nums[n - 1 ] * nums[n - 2 ] - nums[0 ] * nums[1 ];
7
+ }
8
+ };
Original file line number Diff line number Diff line change
1
+ func maxProductDifference (nums []int ) int {
2
+ sort .Ints (nums )
3
+ n := len (nums )
4
+ return nums [n - 1 ]* nums [n - 2 ] - nums [0 ]* nums [1 ]
5
+ }
You can’t perform that action at this time.
0 commit comments