Skip to content

Commit 63f5254

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent b69ef3c commit 63f5254

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# it's a leetcode question no. 2561 where You have two fruit baskets containing n fruits each. You are given two 0-indexed integer arrays basket1 and basket2 representing the cost of fruit in each basket.
1+
# it's a leetcode question no. 2561 where You have two fruit baskets containing n fruits each. You are given two 0-indexed integer arrays basket1 and basket2 representing the cost of fruit in each basket.
22
# You want to make both baskets equal. To do so, you can use the following operation as many times as you want:
33

44
# Chose two indices i and j, and swap the ith fruit of basket1 with the jth fruit of basket2.
@@ -10,28 +10,30 @@
1010
from typing import List
1111
from collections import defaultdict
1212

13+
1314
class Solution:
1415
def minCost(self, basket1: List[int], basket2: List[int]) -> int:
1516
n = len(basket1)
1617
freq = defaultdict(int)
17-
mn = float('inf')
18+
mn = float("inf")
1819
for i in range(n):
1920
freq[basket1[i]] += 1
2021
freq[basket2[i]] -= 1
2122
mn = min(mn, basket1[i], basket2[i])
22-
23+
2324
to_swap = []
24-
for j,k in freq.items():
25+
for j, k in freq.items():
2526
if k % 2 != 0:
2627
return -1
2728
to_swap += [j] * (abs(k) // 2)
28-
29+
2930
to_swap.sort()
3031
res = 0
3132
for i in range(len(to_swap) // 2):
3233
res += min(to_swap[i], 2 * mn)
33-
34+
3435
return res
3536

37+
3638
s = Solution()
3739
print(s.minCost([4, 2, 2, 2], [1, 4, 1, 2])) # Output: 1

0 commit comments

Comments
 (0)