Skip to content

Commit 53a5b6d

Browse files
committed
feat: add solutions to lc/lcof problems
1 parent 7b4fa56 commit 53a5b6d

File tree

6 files changed

+84
-0
lines changed

6 files changed

+84
-0
lines changed

lcof/面试题64. 求1+2+…+n/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ var sumNums = function (n) {
6060
};
6161
```
6262

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+
6378
### **...**
6479

6580
```
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}

solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,29 @@ var maxProductDifference = function(nums) {
9090
};
9191
```
9292

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+
93116
### **...**
94117

95118
```

solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README_EN.md

+23
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,29 @@ var maxProductDifference = function(nums) {
111111
};
112112
```
113113

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+
114137
### **...**
115138

116139
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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+
}

0 commit comments

Comments
 (0)