Skip to content

Commit

Permalink
add 1196
Browse files Browse the repository at this point in the history
  • Loading branch information
luliyucoordinate committed Sep 23, 2019
1 parent 13ec934 commit 8e4689e
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,4 +500,5 @@ LeetCode
|1189|[Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons/) | c | [c++](./src/1189-Maximum-Number-of-Balloons/1189.cpp) |[python](./src/1189-Maximum-Number-of-Balloons/1189.py)|[go](./src/1189-Maximum-Number-of-Balloons/1189.go)|[js](./src/1189-Maximum-Number-of-Balloons/1189.js)|Easy|
|1190|[Reverse Substrings Between Each Pair of Parentheses](https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses/) | c | [c++](./src/1190-Reverse-Substrings-Between-Each-Pair-of-Parentheses/1190.cpp) |[python](./src/1190-Reverse-Substrings-Between-Each-Pair-of-Parentheses/1190.py)|[go](./src/1190-Reverse-Substrings-Between-Each-Pair-of-Parentheses/1190.go)|[js](./src/1190-Reverse-Substrings-Between-Each-Pair-of-Parentheses/1190.js)|Medium|
|1191|[K-Concatenation Maximum Sum](https://leetcode.com/problems/k-concatenation-maximum-sum/) | c | [c++](./src/1191-K-Concatenation-Maximum-Sum/1191.cpp) |[python](./src/1191-K-Concatenation-Maximum-Sum/1191.py)|[go](./src/1191-K-Concatenation-Maximum-Sum/1191.go)|[js](./src/1191-K-Concatenation-Maximum-Sum/1191.js)|Medium|
|1192|[Critical Connections in a Network](https://leetcode.com/problems/critical-connections-in-a-network/) | c | [c++](./src/1192-Critical-Connections-in-a-Network/1192.cpp) |[python](./src/1192-Critical-Connections-in-a-Network/1192.py)|[go](./src/1192-Critical-Connections-in-a-Network/1192.go)|[js](./src/1192-Critical-Connections-in-a-Network/1192.js)|Hard|
|1192|[Critical Connections in a Network](https://leetcode.com/problems/critical-connections-in-a-network/) | c | [c++](./src/1192-Critical-Connections-in-a-Network/1192.cpp) |[python](./src/1192-Critical-Connections-in-a-Network/1192.py)|[go](./src/1192-Critical-Connections-in-a-Network/1192.go)|[js](./src/1192-Critical-Connections-in-a-Network/1192.js)|Hard|
|1196|[How Many Apples Can You Put into the Basket](https://leetcode.com/contest/biweekly-contest-9/problems/how-many-apples-can-you-put-into-the-basket/) | c | [c++](./src/1196-How-Many-Apples-Can-You-Put-into-the-Basket/1196.cpp) |[python](./src/1196-How-Many-Apples-Can-You-Put-into-the-Basket/1196.py)|[go](./src/1196-How-Many-Apples-Can-You-Put-into-the-Basket/1196.go)|[js](./src/1196-How-Many-Apples-Can-You-Put-into-the-Basket/1196.js)|Easy|
16 changes: 16 additions & 0 deletions src/1196-How-Many-Apples-Can-You-Put-into-the-Basket/1196.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution
{
public:
int maxNumberOfApples(vector<int>& arr)
{
sort(arr.begin(), arr.end());
int res = 0, t = 0;
for (int i : arr)
{
t += i;
if (t > 5000) break;
res++;
}
return res;
}
};
26 changes: 26 additions & 0 deletions src/1196-How-Many-Apples-Can-You-Put-into-the-Basket/1196.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
func maxNumberOfApples(arr []int) int {
sort.Sort(IntSlice(arr))
res, t := 0, 0
for _, v := range arr {
t += v
if t > 5000 {
break
}
res++
}
return res
}

type IntSlice []int

func (s IntSlice) Len() int {
return len(s)
}

func (s IntSlice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

func (s IntSlice) Less(i, j int) bool {
return s[i] < s[j]
}
12 changes: 12 additions & 0 deletions src/1196-How-Many-Apples-Can-You-Put-into-the-Basket/1196.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var maxNumberOfApples = function(arr) {
arr.sort(function sortNumber(a,b) {
return a - b;
});
var res = 0, t = 0;
for (let i of arr) {
t += i;
if (t > 5000) break;
res++;
}
return res;
};
10 changes: 10 additions & 0 deletions src/1196-How-Many-Apples-Can-You-Put-into-the-Basket/1196.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution:
def maxNumberOfApples(self, arr: List[int]) -> int:
arr.sort()
res, t = 0, 0
for v in arr:
t += v
if t > 5000:
break
res += 1
return res

0 comments on commit 8e4689e

Please sign in to comment.