Skip to content

Commit 015c1ba

Browse files
committed
Time: 7 ms (43.59%), Space: 18 MB (33.33%) - LeetHub
1 parent 1de0d27 commit 015c1ba

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# time complexity: O(n^2)
2+
# space complexity: O(n)
3+
class Solution:
4+
def maximumNumberOfOnes(self, width: int, height: int, sideLength: int, maxOnes: int) -> int:
5+
count = []
6+
for r in range(sideLength):
7+
for c in range(sideLength):
8+
num = (1+(width - c - 1) // sideLength) * \
9+
(1+(height-r-1)//sideLength)
10+
count.append(num)
11+
count.sort(reverse=True)
12+
return sum(count[:maxOnes])
13+
14+
15+
width = 3
16+
height = 3
17+
sideLength = 2
18+
maxOnes = 1
19+
print(Solution().maximumNumberOfOnes(width, height, sideLength, maxOnes))
20+
width = 3
21+
height = 3
22+
sideLength = 2
23+
maxOnes = 2
24+
print(Solution().maximumNumberOfOnes(width, height, sideLength, maxOnes))

0 commit comments

Comments
 (0)