Skip to content

Commit 2ff8b3f

Browse files
committed
feat: add solutions to lc problem: No.1196
No.1196.How Many Apples Can You Put into the Basket
1 parent b90b376 commit 2ff8b3f

File tree

8 files changed

+175
-4
lines changed

8 files changed

+175
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
## 站点
2222

23-
- Vercel: https://leetcode-doocs.vercel.app
23+
- Vercel: https://doocs-leetcode.vercel.app
2424
- GitHub Pages: https://doocs.github.io/leetcode
2525

2626
## 算法全解

README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Complete solutions to [LeetCode](https://leetcode.com/problemset/all/), [LCOF](h
2020

2121
## Sites
2222

23-
- Vercel: https://leetcode-doocs.vercel.app
23+
- Vercel: https://doocs-leetcode.vercel.app
2424
- GitHub Pages: https://doocs.github.io/leetcode
2525

2626
## Solutions

solution/1100-1199/1196.How Many Apples Can You Put into the Basket/README.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,83 @@
4141

4242
<!-- 这里可写通用的实现逻辑 -->
4343

44+
**方法一:排序**
45+
4446
<!-- tabs:start -->
4547

4648
### **Python3**
4749

4850
<!-- 这里可写当前语言的特殊实现逻辑 -->
4951

5052
```python
51-
53+
class Solution:
54+
def maxNumberOfApples(self, weight: List[int]) -> int:
55+
weight.sort()
56+
ans = 0
57+
t = 0
58+
for v in weight:
59+
if t + v > 5000:
60+
break
61+
t += v
62+
ans += 1
63+
return ans
5264
```
5365

5466
### **Java**
5567

5668
<!-- 这里可写当前语言的特殊实现逻辑 -->
5769

5870
```java
71+
class Solution {
72+
public int maxNumberOfApples(int[] weight) {
73+
Arrays.sort(weight);
74+
int ans = 0, t = 0;
75+
for (int v : weight) {
76+
if (t + v > 5000) {
77+
break;
78+
}
79+
t += v;
80+
++ans;
81+
}
82+
return ans;
83+
}
84+
}
85+
```
86+
87+
### **C++**
88+
89+
```cpp
90+
class Solution {
91+
public:
92+
int maxNumberOfApples(vector<int>& weight) {
93+
sort(weight.begin(), weight.end());
94+
int ans = 0, t = 0;
95+
for (int v : weight)
96+
{
97+
if (t + v > 5000) break;
98+
t += v;
99+
++ans;
100+
}
101+
return ans;
102+
}
103+
};
104+
```
59105
106+
### **Go**
107+
108+
```go
109+
func maxNumberOfApples(weight []int) int {
110+
sort.Ints(weight)
111+
ans, t := 0, 0
112+
for _, v := range weight {
113+
if t+v > 5000 {
114+
break
115+
}
116+
t += v
117+
ans++
118+
}
119+
return ans
120+
}
60121
```
61122

62123
### **...**

solution/1100-1199/1196.How Many Apples Can You Put into the Basket/README_EN.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,72 @@
4040
### **Python3**
4141

4242
```python
43-
43+
class Solution:
44+
def maxNumberOfApples(self, weight: List[int]) -> int:
45+
weight.sort()
46+
ans = 0
47+
t = 0
48+
for v in weight:
49+
if t + v > 5000:
50+
break
51+
t += v
52+
ans += 1
53+
return ans
4454
```
4555

4656
### **Java**
4757

4858
```java
59+
class Solution {
60+
public int maxNumberOfApples(int[] weight) {
61+
Arrays.sort(weight);
62+
int ans = 0, t = 0;
63+
for (int v : weight) {
64+
if (t + v > 5000) {
65+
break;
66+
}
67+
t += v;
68+
++ans;
69+
}
70+
return ans;
71+
}
72+
}
73+
```
74+
75+
### **C++**
76+
77+
```cpp
78+
class Solution {
79+
public:
80+
int maxNumberOfApples(vector<int>& weight) {
81+
sort(weight.begin(), weight.end());
82+
int ans = 0, t = 0;
83+
for (int v : weight)
84+
{
85+
if (t + v > 5000) break;
86+
t += v;
87+
++ans;
88+
}
89+
return ans;
90+
}
91+
};
92+
```
4993
94+
### **Go**
95+
96+
```go
97+
func maxNumberOfApples(weight []int) int {
98+
sort.Ints(weight)
99+
ans, t := 0, 0
100+
for _, v := range weight {
101+
if t+v > 5000 {
102+
break
103+
}
104+
t += v
105+
ans++
106+
}
107+
return ans
108+
}
50109
```
51110

52111
### **...**
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
int maxNumberOfApples(vector<int>& weight) {
4+
sort(weight.begin(), weight.end());
5+
int ans = 0, t = 0;
6+
for (int v : weight)
7+
{
8+
if (t + v > 5000) break;
9+
t += v;
10+
++ans;
11+
}
12+
return ans;
13+
}
14+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
func maxNumberOfApples(weight []int) int {
2+
sort.Ints(weight)
3+
ans, t := 0, 0
4+
for _, v := range weight {
5+
if t+v > 5000 {
6+
break
7+
}
8+
t += v
9+
ans++
10+
}
11+
return ans
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int maxNumberOfApples(int[] weight) {
3+
Arrays.sort(weight);
4+
int ans = 0, t = 0;
5+
for (int v : weight) {
6+
if (t + v > 5000) {
7+
break;
8+
}
9+
t += v;
10+
++ans;
11+
}
12+
return ans;
13+
}
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def maxNumberOfApples(self, weight: List[int]) -> int:
3+
weight.sort()
4+
ans = 0
5+
t = 0
6+
for v in weight:
7+
if t + v > 5000:
8+
break
9+
t += v
10+
ans += 1
11+
return ans

0 commit comments

Comments
 (0)